|
1 | | -// Complete declarative AutoQuery services for Bookings CRUD example: |
2 | | -// https://docs.servicestack.net/autoquery-crud-bookings |
3 | | - |
4 | 1 | using System; |
| 2 | +using System.IO; |
| 3 | +using System.Collections; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Runtime.Serialization; |
5 | 6 | using ServiceStack; |
6 | 7 | using ServiceStack.DataAnnotations; |
| 8 | +using MyApp; |
7 | 9 |
|
8 | 10 | namespace MyApp.ServiceModel; |
9 | 11 |
|
10 | | -[Icon(Svg = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M16 10H8c-.55 0-1 .45-1 1s.45 1 1 1h8c.55 0 1-.45 1-1s-.45-1-1-1zm3-7h-1V2c0-.55-.45-1-1-1s-1 .45-1 1v1H8V2c0-.55-.45-1-1-1s-1 .45-1 1v1H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-1 16H6c-.55 0-1-.45-1-1V8h14v10c0 .55-.45 1-1 1zm-5-5H8c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1s-.45-1-1-1z'/></svg>")] |
11 | | -[Description("Booking Details")] |
12 | | -[Notes("Captures a Persons Name & Room Booking information")] |
13 | | -public class Booking : AuditBase |
14 | | -{ |
15 | | - [AutoIncrement] |
16 | | - public int Id { get; set; } |
17 | | - public string Name { get; set; } |
18 | | - public RoomType RoomType { get; set; } |
19 | | - public int RoomNumber { get; set; } |
20 | | - [IntlDateTime(DateStyle.Long)] |
21 | | - public DateTime BookingStartDate { get; set; } |
22 | | - [IntlRelativeTime] |
23 | | - public DateTime? BookingEndDate { get; set; } |
24 | | - [IntlNumber(Currency = NumberCurrency.USD)] |
25 | | - public decimal Cost { get; set; } |
26 | | - |
27 | | - [Ref(Model = nameof(Coupon), RefId = nameof(Coupon.Id), RefLabel = nameof(Coupon.Description))] |
28 | | - [References(typeof(Coupon))] |
29 | | - public string? CouponId { get; set; } |
30 | | - |
31 | | - [Reference] |
32 | | - public Coupon Discount { get; set; } |
33 | | - public string? Notes { get; set; } |
34 | | - public bool? Cancelled { get; set; } |
35 | | - |
36 | | - [Reference(SelfId = nameof(CreatedBy), RefId = nameof(User.UserName), RefLabel = nameof(User.DisplayName))] |
37 | | - public User Employee { get; set; } |
38 | | -} |
39 | | - |
40 | | -public enum RoomType |
41 | | -{ |
42 | | - Single, |
43 | | - Double, |
44 | | - Queen, |
45 | | - Twin, |
46 | | - Suite, |
47 | | -} |
48 | | - |
49 | | -[Tag("bookings"), Description("Find Bookings")] |
50 | | -[Notes("Find out how to quickly create a <a class='svg-external' target='_blank' href='https://youtu.be/nhc4MZufkcM'>C# Bookings App from Scratch</a>")] |
51 | | -[Route("/bookings", "GET")] |
52 | | -[Route("/bookings/{Id}", "GET")] |
| 12 | +[Tag("Bookings")] |
| 13 | +[Route("/bookings/{Id}","GET")] |
| 14 | +[Route("/bookings","GET")] |
53 | 15 | [AutoApply(Behavior.AuditQuery)] |
54 | | -public class QueryBookings : QueryDb<Booking> |
| 16 | +[ValidateHasRole("Employee")] |
| 17 | +public class QueryBookings : QueryDb<Booking> |
55 | 18 | { |
56 | 19 | public int? Id { get; set; } |
| 20 | + public List<int>? Ids { get; set; } |
57 | 21 | } |
58 | 22 |
|
59 | | -// Uncomment below to enable DeletedBookings API to view deleted bookings: |
60 | | -// [Route("/bookings/deleted")] |
61 | | -// [AutoFilter(QueryTerm.Ensure, nameof(AuditBase.DeletedDate), Template = SqlTemplate.IsNotNull)] |
62 | | -// public class DeletedBookings : QueryDb<Booking> {} |
63 | | - |
64 | | -[Tag("bookings"), Description("Create a new Booking")] |
65 | | -[LocodeCss(Field="col-span-12 sm:col-span-6", Fieldset = "grid grid-cols-8 gap-2", Form = "border overflow-hidden max-w-screen-lg")] |
66 | | -[ExplorerCss(Field="col-span-12 sm:col-span-6", Fieldset = "grid grid-cols-6 gap-8", Form = "border border-indigo-500 overflow-hidden max-w-screen-lg")] |
67 | | -[Route("/bookings", "POST")] |
68 | | -[ValidateHasRole("Employee")] |
| 23 | +[Tag("Bookings")] |
| 24 | +[Route("/bookings","POST")] |
69 | 25 | [AutoApply(Behavior.AuditCreate)] |
| 26 | +[Description("Create a new Booking")] |
| 27 | +[ValidateHasRole("Employee")] |
70 | 28 | public class CreateBooking : ICreateDb<Booking>, IReturn<IdResponse> |
71 | 29 | { |
72 | | - [Description("Name this Booking is for"), ValidateNotEmpty] |
| 30 | + [ValidateNotEmpty] |
73 | 31 | public string Name { get; set; } |
74 | 32 | public RoomType RoomType { get; set; } |
75 | 33 | [ValidateGreaterThan(0)] |
76 | 34 | public int RoomNumber { get; set; } |
77 | | - [ValidateGreaterThan(0)] |
78 | | - public decimal Cost { get; set; } |
79 | | - [Required] |
80 | 35 | public DateTime BookingStartDate { get; set; } |
81 | 36 | public DateTime? BookingEndDate { get; set; } |
82 | | - [Input(Type = "textarea")] |
83 | | - public string? Notes { get; set; } |
| 37 | + [ValidateGreaterThan(0)] |
| 38 | + public decimal Cost { get; set; } |
84 | 39 | public string? CouponId { get; set; } |
| 40 | + [Input(Type="textarea")] |
| 41 | + public string? Notes { get; set; } |
| 42 | + public bool? Cancelled { get; set; } |
85 | 43 | } |
86 | 44 |
|
87 | | -[Tag("bookings"), Description("Update an existing Booking")] |
| 45 | +[Tag("Bookings")] |
88 | 46 | [Notes("Find out how to quickly create a <a class='svg-external' target='_blank' href='https://youtu.be/nhc4MZufkcM'>C# Bookings App from Scratch</a>")] |
89 | | -[Route("/booking/{Id}", "PATCH")] |
90 | | -[ValidateHasRole("Employee")] |
| 47 | +[Route("/booking/{Id}","PATCH")] |
91 | 48 | [AutoApply(Behavior.AuditModify)] |
| 49 | +[Description("Update an existing Booking")] |
| 50 | +[ValidateHasRole("Employee")] |
92 | 51 | public class UpdateBooking : IPatchDb<Booking>, IReturn<IdResponse> |
93 | 52 | { |
94 | 53 | public int Id { get; set; } |
95 | 54 | public string? Name { get; set; } |
96 | 55 | public RoomType? RoomType { get; set; } |
97 | 56 | [ValidateGreaterThan(0)] |
98 | 57 | public int? RoomNumber { get; set; } |
99 | | - [ValidateGreaterThan(0)] |
100 | | - public decimal? Cost { get; set; } |
101 | 58 | public DateTime? BookingStartDate { get; set; } |
102 | 59 | public DateTime? BookingEndDate { get; set; } |
103 | | - [Input(Type = "textarea")] |
104 | | - public string? Notes { get; set; } |
| 60 | + [ValidateGreaterThan(0)] |
| 61 | + public decimal? Cost { get; set; } |
105 | 62 | public string? CouponId { get; set; } |
| 63 | + [Input(Type="textarea")] |
| 64 | + public string? Notes { get; set; } |
106 | 65 | public bool? Cancelled { get; set; } |
107 | 66 | } |
108 | 67 |
|
109 | | -[Tag("bookings"), Description("Delete a Booking")] |
110 | | -[Route("/booking/{Id}", "DELETE")] |
111 | | -[ValidateHasRole("Manager")] |
| 68 | +[Tag("Bookings")] |
| 69 | +[Route("/booking/{Id}","DELETE")] |
112 | 70 | [AutoApply(Behavior.AuditSoftDelete)] |
| 71 | +[Description("Delete a Booking")] |
| 72 | +[ValidateHasRole("Employee")] |
113 | 73 | public class DeleteBooking : IDeleteDb<Booking>, IReturnVoid |
114 | 74 | { |
115 | | - public int Id { get; set; } |
116 | | -} |
117 | | - |
118 | | - |
119 | | -[Description("Discount Coupons")] |
120 | | -[Icon(Svg = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M2 9.5V4a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v5.5a2.5 2.5 0 1 0 0 5V20a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-5.5a2.5 2.5 0 1 0 0-5zm2-1.532a4.5 4.5 0 0 1 0 8.064V19h16v-2.968a4.5 4.5 0 0 1 0-8.064V5H4v2.968zM9 9h6v2H9V9zm0 4h6v2H9v-2z' /></svg>")] |
121 | | -public class Coupon |
122 | | -{ |
123 | | - public string Id { get; set; } |
124 | | - public string Description { get; set; } |
125 | | - public int Discount { get; set; } |
126 | | - public DateTime ExpiryDate { get; set; } |
| 75 | + public int? Id { get; set; } |
| 76 | + public List<int>? Ids { get; set; } |
127 | 77 | } |
128 | 78 |
|
129 | | -[Tag("bookings"), Description("Find Coupons")] |
130 | | -[Route("/coupons", "GET")] |
| 79 | +[Tag("Bookings")] |
| 80 | +[AutoApply(Behavior.AuditQuery)] |
131 | 81 | public class QueryCoupons : QueryDb<Coupon> |
132 | 82 | { |
133 | | - public string Id { get; set; } |
| 83 | + public string? Id { get; set; } |
| 84 | + public List<string>? Ids { get; set; } |
134 | 85 | } |
135 | 86 |
|
136 | | -[Tag("bookings")] |
137 | | -[Route("/coupons", "POST")] |
138 | | -[ValidateHasRole("Employee")] |
| 87 | +[Tag("Bookings")] |
| 88 | +[AutoApply(Behavior.AuditCreate)] |
| 89 | +[ValidateIsAuthenticated] |
139 | 90 | public class CreateCoupon : ICreateDb<Coupon>, IReturn<IdResponse> |
140 | 91 | { |
141 | 92 | [ValidateNotEmpty] |
142 | 93 | public string Id { get; set; } |
143 | 94 | [ValidateNotEmpty] |
144 | 95 | public string Description { get; set; } |
145 | | - [ValidateGreaterThan(0)] |
146 | | - public int Discount { get; set; } |
147 | | - [ValidateNotNull] |
| 96 | + public decimal Discount { get; set; } |
148 | 97 | public DateTime ExpiryDate { get; set; } |
149 | 98 | } |
150 | 99 |
|
151 | | -[Tag("bookings")] |
152 | | -[Route("/coupons/{Id}", "PATCH")] |
153 | | -[ValidateHasRole("Employee")] |
| 100 | +[Tag("Bookings")] |
| 101 | +[AutoApply(Behavior.AuditModify)] |
| 102 | +[ValidateIsAuthenticated] |
154 | 103 | public class UpdateCoupon : IPatchDb<Coupon>, IReturn<IdResponse> |
155 | 104 | { |
156 | 105 | public string Id { get; set; } |
157 | | - [ValidateNotEmpty] |
158 | 106 | public string? Description { get; set; } |
159 | | - [ValidateNotNull, ValidateGreaterThan(0)] |
160 | | - public int? Discount { get; set; } |
161 | | - [ValidateNotNull] |
| 107 | + public decimal? Discount { get; set; } |
162 | 108 | public DateTime? ExpiryDate { get; set; } |
163 | 109 | } |
164 | 110 |
|
165 | | -[Tag("bookings"), Description("Delete a Coupon")] |
166 | | -[Route("/coupons/{Id}", "DELETE")] |
167 | | -[ValidateHasRole("Manager")] |
| 111 | +[Tag("Bookings")] |
| 112 | +[AutoApply(Behavior.AuditSoftDelete)] |
| 113 | +[ValidateIsAuthenticated] |
168 | 114 | public class DeleteCoupon : IDeleteDb<Coupon>, IReturnVoid |
169 | 115 | { |
170 | | - public string Id { get; set; } |
| 116 | + public string? Id { get; set; } |
| 117 | + public List<string>? Ids { get; set; } |
171 | 118 | } |
172 | 119 |
|
173 | | -public class AdminData : IGet, IReturn<AdminDataResponse> {} |
174 | 120 |
|
175 | | -public class PageStats |
| 121 | +[Icon(Svg="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M16 10H8c-.55 0-1 .45-1 1s.45 1 1 1h8c.55 0 1-.45 1-1s-.45-1-1-1zm3-7h-1V2c0-.55-.45-1-1-1s-1 .45-1 1v1H8V2c0-.55-.45-1-1-1s-1 .45-1 1v1H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-1 16H6c-.55 0-1-.45-1-1V8h14v10c0 .55-.45 1-1 1zm-5-5H8c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1s-.45-1-1-1z'/></svg>")] |
| 122 | +[Notes("Captures a Persons Name & Room Booking information")] |
| 123 | +[Description("Booking Details")] |
| 124 | +public class Booking : AuditBase |
| 125 | +{ |
| 126 | + [AutoIncrement] |
| 127 | + public int Id { get; set; } |
| 128 | + public string Name { get; set; } |
| 129 | + public RoomType RoomType { get; set; } |
| 130 | + public int RoomNumber { get; set; } |
| 131 | + [IntlDateTime(DateStyle.Long)] |
| 132 | + public DateTime BookingStartDate { get; set; } |
| 133 | + [IntlRelativeTime] |
| 134 | + public DateTime? BookingEndDate { get; set; } |
| 135 | + [IntlNumber(Currency="USD")] |
| 136 | + public decimal Cost { get; set; } |
| 137 | + [Ref(Model=nameof(Coupon),RefId=nameof(Coupon.Id),RefLabel=nameof(Coupon.Description))] |
| 138 | + [References(typeof(Coupon))] |
| 139 | + public string? CouponId { get; set; } |
| 140 | + [Format(FormatMethods.Hidden)] |
| 141 | + [Reference] |
| 142 | + public Coupon? Discount { get; set; } |
| 143 | + public string? Notes { get; set; } |
| 144 | + public bool? Cancelled { get; set; } |
| 145 | + [Format(FormatMethods.Hidden)] |
| 146 | + [Reference(SelfId=nameof(CreatedBy),RefId=nameof(User.UserName),RefLabel=nameof(User.DisplayName))] |
| 147 | + public User Employee { get; set; } |
| 148 | +} |
| 149 | + |
| 150 | +[Icon(Svg="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M2 9.5V4a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v5.5a2.5 2.5 0 1 0 0 5V20a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-5.5a2.5 2.5 0 1 0 0-5zm2-1.532a4.5 4.5 0 0 1 0 8.064V19h16v-2.968a4.5 4.5 0 0 1 0-8.064V5H4v2.968zM9 9h6v2H9V9zm0 4h6v2H9v-2z' /></svg>")] |
| 151 | +public class Coupon : AuditBase |
176 | 152 | { |
177 | | - public string Label { get; set; } |
178 | | - public int Total { get; set; } |
| 153 | + public string Id { get; set; } |
| 154 | + public string Description { get; set; } |
| 155 | + public decimal Discount { get; set; } |
| 156 | + public DateTime ExpiryDate { get; set; } |
179 | 157 | } |
180 | 158 |
|
181 | | -public class AdminDataResponse |
| 159 | + |
| 160 | +public enum RoomType |
182 | 161 | { |
183 | | - public List<PageStats> PageStats { get; set; } |
| 162 | + Single, |
| 163 | + Double, |
| 164 | + Queen, |
| 165 | + Twin, |
| 166 | + Suite, |
184 | 167 | } |
| 168 | + |
0 commit comments