public ActionResult Create([Bind(Include = "ID,Name,CustomerCode,Province,Address1,Address2,PhoneNumber1,PhoneNumber2,Email,Company,Department,Image,DateOfBirth,Gender,CurrentDebt,BonusPoint,TaxCode,ManagedBy,Group")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Appointments_Create([DataSourceRequest] DataSourceRequest request, AppointmentViewModel appointment) { if (string.IsNullOrEmpty(appointment.Title)) { appointment.Title = ""; } string status = "booking"; if (appointment.RoomID == null) { status = "waiting"; } Customer C = new Customer(); var entity = appointment.ToEntity(); C = db.Customers.Where(x => x.ID == appointment.CustomerID).FirstOrDefault(); var isbooking = db.Appointments.Where(x => x.RoomID == appointment.RoomID && x.Status != "cancelled") .Any(s => (s.Start >= appointment.Start && s.End <= appointment.End) || (s.End <= appointment.End && s.End >= appointment.Start)); if (C != null && !isbooking) { C.Name = appointment.Title; entity.Status = status; db.Appointments.Add(entity); db.Entry(C).State = EntityState.Modified; db.SaveChanges(); appointment.ID = entity.ID; } appointment.IsBooked = isbooking; // } return(Json(new[] { appointment }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet)); }