public void Add(TEntity entity) { var entry = _context.Entry(entity); entry.State = EntityState.Added; _context.SaveChanges(); Dispose(); }
public JsonResult SaveEvent(Appointment data) { _ctx.Configuration.ProxyCreationEnabled = false; var status = false; if (data.AppointmentID > 0) { Appointment oldEvent = _ctx.Appointment.Where(x => x.AppointmentID == data.AppointmentID).FirstOrDefault(); if (oldEvent != null) { oldEvent.ExpertID = data.ExpertID; oldEvent.ClientID = data.ClientID; oldEvent.Subject = data.Subject; oldEvent.Description = data.Description == null ? "" : data.Description; oldEvent.ThemeColor = data.ThemeColor; oldEvent.IsFullDay = data.IsFullDay; oldEvent.EndTime = data.EndTime; oldEvent.StartTime = data.StartTime; } } else { _ctx.Appointment.Add(data); } _ctx.SaveChanges(); status = true; return new JsonResult { Data = new { status = status } }; }
public ActionResult Post([FromBody] AppointmentCreate dto) { // If All Required Fields present if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Date should be future if (dto.Date < DateTime.Today) { ModelState.AddModelError("Date", "Min Date is Today"); return(BadRequest(ModelState)); } // Time Range if (dto.Date.Hour < 9 && dto.Date.Hour > 18) { ModelState.AddModelError("Time", "Time should be between 9AM and 6PM"); return(BadRequest(ModelState)); } // One appointment per day per doctor if (context.Appointments.Any(X => X.DoctorId == dto.DoctorId && X.Date.Date == dto.Date.Date)) { ModelState.AddModelError("DoctorId", "Only One Appointment Per Doctor Per Day"); return(BadRequest(ModelState)); } // Limit Appointment Per Week var week = System.Globalization.ISOWeek.GetWeekOfYear(dto.Date); if (context.Appointments.Where(X => System.Globalization.ISOWeek.GetWeekOfYear(X.Date) == week).Count() > 5) { ModelState.AddModelError("Date", "Maximum Appointments Should be 5 per week"); return(BadRequest(ModelState)); } var entity = new Data.Entities.Appointment { Name = dto.Name, Date = dto.Date, Email = dto.Email, Message = dto.Message, DoctorId = dto.DoctorId }; context.Appointments.Add(entity); context.SaveChanges(); return(Ok()); }
public void Post([FromBody] TblAppointment value) { bool appointmentClash = ValidateNoAppoinmentClash(value); if (appointmentClash == true) { db.TblPatients.Add(value.AppointmentPatient); db.TblAppointments.Add(value); db.SaveChanges(); } else { throw new Exception("Seçtiğiniz tarih aralığında doktorumuz müsait değildir."); } }
public JsonResult DeleteEvent(int id) { var status = false; using (AppointmentDBContext dc = new AppointmentDBContext()) { Appointment deletedEvent = dc.Appointment.Where(x => x.AppointmentID == id).FirstOrDefault(); if (deletedEvent != null) { dc.Appointment.Remove(deletedEvent); dc.SaveChanges(); status = true; } } return new JsonResult { Data = new { status = status } }; }
public void PrepareItems() { var doctors = new List <Doctor> { new Doctor { Name = "Till Lindemann" }, new Doctor { Name = "Richard Z. Kruspe" }, new Doctor { Name = "Paul H. Landers" } }; context.Doctors.AddRange(doctors); context.SaveChanges(); }
public ActionResult Edit([Bind(Include = "ID, patients_pesel, estim_disease, real_disease, dis_descript, appoint_date, specialization, docs_pesel, service_type, service_name, service_price, is_paid, supplies_price")] Appointment appointment) { AppointmentDBContext context = new AppointmentDBContext(); if (ModelState.IsValid) { double time = -1; context.Entry(appointment).State = EntityState.Modified; context.SaveChanges(); string query = "UPDATE [dbo].[AppointmentsArch] SET DBUSer = '******' WHERE Idd = '" + appointment.ID + "' AND TypeOfChange = 'UPDATED-INSERTED' AND DateOfChange >= '" + DateTime.Now.AddSeconds(time) + "'"; db.Database.ExecuteSqlCommand(query); query = "UPDATE [dbo].[AppointmentsArch] SET DBUSer = '******' WHERE Idd = '" + appointment.ID + "' AND TypeOfChange = 'UPDATED-DELETED' AND DateOfChange >= '" + DateTime.Now.AddSeconds(time) + "'"; db.Database.ExecuteSqlCommand(query); return(RedirectToAction("Index")); } return(View(appointment)); }