private static Guid AddBooking(Booking booking) { using (var db = new ApplicationDbContext()) { db.Bookings.Add(booking); db.SaveChanges(); return booking.Id; } }
public Guid PutBooking(Booking booking) { var guid = SaveBooking(booking); if (guid.IsNull()) { return Guid.Empty; } var requestEmailBody = ConfigurationManager.AppSettings["RequestEmail"].Replace("{reference}", $"{guid}"); var notificationEmail = ConfigurationManager.AppSettings["NotificationEmail"].Replace("{name}", booking.Name).Replace("{date}", $"{booking.Date}"); Mailer.SendEmail(booking.Email, "Warboar Booking Request", requestEmailBody); Mailer.SendEmail(ConfigurationManager.AppSettings["EmailFrom"], "New Booking Notification", notificationEmail); return guid; }
private static Guid UpdateBooking(Booking booking) { using (var db = new ApplicationDbContext()) { var dbBooking = db.Bookings.Find(booking.Id); dbBooking.Name = booking.Name; dbBooking.Email = booking.Email; dbBooking.Mobile = booking.Mobile; dbBooking.GameType = booking.GameType; dbBooking.Size = booking.Size; dbBooking.NumberOfTables = booking.NumberOfTables; dbBooking.Date = booking.Date; dbBooking.AdditionalComments = booking.AdditionalComments; dbBooking.Status = booking.Status; db.SaveChanges(); return dbBooking.Id; } }
private static Guid SaveBooking(Booking booking) { return booking.Id != Guid.Empty ? UpdateBooking(booking) : AddBooking(booking); }