public bool DeleteBooking(string bookingId) { try { int bId = int.Parse(bookingId); BookingEntities ctx = new BookingEntities(); BoatBooking b = ctx.BoatBooking.Where(x => x.Id == bId).First(); BookingCancelledModel cm = new BookingCancelledModel { UserEmail = b.Member.Email, UserName = b.Member.Name, SailingClub = ConfigurationManager.AppSettings["SailingClub"], Signature = ConfigurationManager.AppSettings["Signature"], BookingReference = b.BookingMemberId.ToString() + "/" + b.Id.ToString(), BookingDate = b.BookingDate }; ctx.BoatBooking.Remove(b); ctx.SaveChanges(); UserMailer um = new UserMailer(); MvcMailMessage msg = um.BoatCancelledTreasurer(cm); msg.Send(); return(true); } catch (Exception) { return(false); } }
public bool BookBoat(string bookingDate, string boatId) { BoatBooking b = null; BookingEntities ctx = null;; try { ctx = new BookingEntities(); int bId = int.Parse(boatId); Member booker = (Member)ctx.Member.Where(m => m.UserProfileId == WebSecurity.CurrentUserId).First(); Boat boat = (Boat)ctx.Boat.Find(bId); DateTime bd = DateTime.Parse(bookingDate); decimal cost = booker.Age < 18 ? 0.0m : boat.RentalCost; b = new BoatBooking { BookingDate = bd, BoatId = boat.Id, BookingMemberId = booker.Id, Units = 1, UnitCost = cost, TotalCost = cost }; ctx.BoatBooking.Add(b); ctx.SaveChanges(); b = ctx.BoatBooking.Where((bb) => bb.BookingMemberId == b.BookingMemberId && bb.BookingDate == b.BookingDate && bb.BoatId == b.BoatId).First(); BoatBookedModel mailModel = new BoatBookedModel { BoatName = boat.Make + " " + boat.Class + " " + boat.SailNumber, BookingDate = bd, Cost = cost, UserEmail = booker.Email, UserName = booker.Name, SailingClub = ConfigurationManager.AppSettings["SailingClub"], Signature = ConfigurationManager.AppSettings["Signature"], BookingReference = b.BookingMemberId.ToString() + "/" + b.Id.ToString() }; UserMailer um = new UserMailer(); MvcMailMessage msgUser = um.BoatBookedUser(mailModel); MvcMailMessage msgTreasurer = um.BoatBookedTreasurer(mailModel); msgUser.Send(); msgTreasurer.Send(); return(true); } catch { if (b != null && b.Id > 0) { if (ctx != null) { ctx.BoatBooking.Remove(b); ctx.SaveChanges(); } } return(false); } finally { if (ctx != null) { ctx.Dispose(); } } }