public ActionResult DeleteConfirmed(int id) { GroomService groomService = db.GroomServices.Find(id); db.GroomServices.Remove(groomService); db.SaveChanges(); return(RedirectToAction("Index")); }
// public ActionResult Update(int id) { string query = "select * from GroomServices where GroomServiceID = @id"; var parameter = new SqlParameter("@id", id); GroomService groomservice = db.GroomServices.SqlQuery(query, parameter).FirstOrDefault(); return(View(groomservice)); }
public ActionResult Edit([Bind(Include = "GroomServiceID,ServiceName,ServiceCost,ServiceDuration")] GroomService groomService) { if (ModelState.IsValid) { db.Entry(groomService).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(groomService)); }
public ActionResult Create([Bind(Include = "GroomServiceID,ServiceName,ServiceCost,ServiceDuration")] GroomService groomService) { if (ModelState.IsValid) { db.GroomServices.Add(groomService); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(groomService)); }
// GET: GroomServices/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GroomService groomService = db.GroomServices.Find(id); if (groomService == null) { return(HttpNotFound()); } return(View(groomService)); }
public ActionResult Update(int id, string BookingDate, string BookingTime, decimal BookingPrice, int PetID, string OwnerID, string GroomerID, int[] BookingServices) { GroomBooking booking = db .GroomBookings .Include(b => b.GroomServices) .FirstOrDefault(b => b.GroomBookingID == id); //remove any existing services attached to this booking foreach (var service in booking.GroomServices.ToList()) { booking.GroomServices.Remove(service); } db.SaveChanges(); //https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings Debug.WriteLine(BookingDate + " " + BookingTime); booking.GroomBookingDate = DateTime.ParseExact(BookingDate + " " + BookingTime, "yyyy-MM-dd Hmm", CultureInfo.InvariantCulture); booking.GroomBookingPrice = (int)(BookingPrice * 100); booking.PetID = PetID; booking.OwnerID = OwnerID; booking.GroomerID = GroomerID; //update the booking db.SaveChanges(); //Microsoft REALLY doesn't like it if you try to enumerate on a null list if (BookingServices != null) { if (BookingServices.Length > 0) { //then re-add the services booking.GroomServices = new List <GroomService>(); //then add services to that booking foreach (int ServiceID in BookingServices) { //Debug.WriteLine("ServiceID is "+ServiceID); GroomService service = db.GroomServices.Find(ServiceID); //Debug.WriteLine("Service Name is "+service.ServiceName); booking.GroomServices.Add(service); } db.SaveChanges(); } } return(RedirectToAction("List")); }
public ActionResult Add(string BookingDate, string BookingTime, decimal BookingPrice, int PetID, string OwnerID, string GroomerID, int[] BookingServices) { GroomBooking newbooking = new GroomBooking(); //https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings Debug.WriteLine(BookingDate + " " + BookingTime); newbooking.GroomBookingDate = DateTime.ParseExact(BookingDate + " " + BookingTime, "yyyy-MM-dd Hmm", CultureInfo.InvariantCulture); newbooking.GroomBookingPrice = (int)(BookingPrice * 100); newbooking.PetID = PetID; newbooking.OwnerID = OwnerID; newbooking.GroomerID = GroomerID; //first add booking db.GroomBookings.Add(newbooking); db.SaveChanges(); //Microsoft REALLY doesn't like it if you try to enumerate on a null list if (BookingServices != null) { if (BookingServices.Length > 0) { newbooking.GroomServices = new List <GroomService>(); //then add services to that booking foreach (int ServiceID in BookingServices.ToList()) { //Debug.WriteLine("ServiceID is "+ServiceID); GroomService service = db.GroomServices.Find(ServiceID); //Debug.WriteLine("Service Name is "+service.ServiceName); newbooking.GroomServices.Add(service); } db.SaveChanges(); } } return(RedirectToAction("List")); }