public int FillAppointmentInfo(Appointment appointment, AppointmentEnumState state) { if (appointment != null) { using (RepositoryAppointment repositoryAppointment = new RepositoryAppointment()) { appointment.State = state; appointment.UpdateTime = DateTime.Now; repositoryAppointment.CUDOperation(appointment, EntityState.Modified); return(repositoryAppointment.SaveChanges()); } } else { return(-1); } }
public int FillAppointmentInfo(Appointment appointment, string description, List <Medicine> prescription, AppointmentEnumState state) { if (appointment != null) { string tempDescription; if (string.IsNullOrEmpty(description.Trim())) { tempDescription = null; } else { tempDescription = description; } using (HospitalContext context = new HospitalContext()) { using (DbContextTransaction transaction = context.Database.BeginTransaction()) { try { appointment.Description = tempDescription; appointment.State = state; appointment.UpdateTime = DateTime.Now; context.Entry(appointment).State = EntityState.Modified; int result = context.SaveChanges(); var tempAppointment = context.Appointments.Include("Medicines").Single(I => I.Id == appointment.Id); foreach (var item in prescription) { var tempMedicine = context.Medicines.Single(I => I.Id == item.Id); tempAppointment.Medicines.Add(tempMedicine); } context.SaveChanges(); transaction.Commit(); return(1); } catch (Exception) { transaction.Rollback(); return(0); } } } } else { return(-1); } }