static void InsertAppointment(dnmvcschedulev02.CarsEFCFDB.CarsDBContext db) { var appointments = db.CarSchedulings.ToList(); var resources = db.Cars.ToList(); var newAppointment = DevExpress.Web.Mvc.SchedulerExtension.GetAppointmentToInsert <dnmvcschedulev02.CarsEFCFDB.CarScheduling>("Scheduler", appointments, resources, AppointmentStorage, ResourceStorage); if (newAppointment == null) { return; } db.CarSchedulings.Add(newAppointment); db.SaveChanges(); // appointments.Add(newAppointment); //var t = appointmentContext.SaveChanges(); }
static void DeleteAppointments(dnmvcschedulev02.CarsEFCFDB.CarsDBContext db) { var appointments = db.CarSchedulings.ToList(); var resources = db.Cars.ToList(); var delAppointments = DevExpress.Web.Mvc.SchedulerExtension.GetAppointmentsToRemove <dnmvcschedulev02.CarsEFCFDB.CarScheduling>("Scheduler", appointments, resources, AppointmentStorage, ResourceStorage); foreach (var appointment in delAppointments) { var delAppointment = appointments.FirstOrDefault(a => a.ID == appointment.ID); if (delAppointment != null) { appointments.Remove(appointment); } } db.SaveChanges(); }
static void UpdateAppointments(dnmvcschedulev02.CarsEFCFDB.CarsDBContext db) { var appointments = db.CarSchedulings.ToList(); var resources = db.Cars.ToList(); var updAppointments = DevExpress.Web.Mvc.SchedulerExtension.GetAppointmentsToUpdate <dnmvcschedulev02.CarsEFCFDB.CarScheduling>("Scheduler", appointments, resources, AppointmentStorage, ResourceStorage); var id_up = updAppointments[0].ID; var objCarsScheduler = db.CarSchedulings.Where(t => t.ID == id_up).FirstOrDefault(); if (objCarsScheduler != null) { //db.CarSchedulings.Attach(updAppointments[0]); db.Entry(objCarsScheduler).CurrentValues.SetValues(updAppointments[0]); //db.Entry(updAppointments).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //foreach (var appointment in updAppointments) //{ //} }
public static void UpdateEditableDataObject(dnmvcschedulev02.CarsEFCFDB.CarsDBContext db) { InsertAppointment(db); UpdateAppointments(db); DeleteAppointments(db); }