示例#1
0
        public ActionResult Appointments_Destroy([DataSourceRequest] DataSourceRequest request, AppointmentViewModel appointment)
        {
            var a = db.Appointments.Find(appointment.ID);

            if (a != null)
            {
                db.Appointments.Remove(a);
                db.SaveChanges();
            }

            return(Json(new[] { appointment }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public ActionResult Appointments_Update([DataSourceRequest] DataSourceRequest request, AppointmentViewModel appointment)
        {
            //if (ModelState.IsValid)
            //{



            if (string.IsNullOrEmpty(appointment.Title))
            {
                appointment.Title = "";
            }

            string status = "booking";

            if (appointment.RoomID == null)
            {
                status = "waiting";
            }
            Customer C      = new Customer();
            var      entity = appointment.ToEntity();

            entity.Status = status;

            var appointments = db.Appointments.Where(x => x.ID == appointment.ID).FirstOrDefault();

            C = db.Customers.Where(x => x.ID == appointment.CustomerID).FirstOrDefault();
            var isbooking = db.Appointments.Where(x => x.RoomID == appointment.RoomID)
                            .Any(s => (s.Start >= appointment.Start && s.End <= appointment.End) ||
                                 (s.End <= appointment.End && s.End >= appointment.Start));

            if (C != null)
            {
                C.Name = appointment.Title;
                if (appointments != null)
                {
                    db.Entry(appointments).State = EntityState.Detached;
                }

                // appointments = entity;

                db.Entry(entity).State = EntityState.Modified;
                db.Entry(C).State      = EntityState.Modified;
                db.SaveChanges();
                appointment.ID = entity.ID;
            }


            appointment.IsBooked = isbooking;
            //   }

            return(Json(new[] { appointment }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public virtual JsonResult Appointments_Destroy([DataSourceRequest] DataSourceRequest request, AppointmentViewModel appointment)
        {
            if (ModelState.IsValid)
            {
                var entity = appointment.ToEntity();
                var a      = db.Appointments.Where(x => x.ID == appointment.ID).FirstOrDefault();
                if (a != null)
                {
                    a.Status = "cancelled";

                    db.Entry(a).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            return(Json(new[] { appointment }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }