public void Update(MedicinePlan medicinePlan, List <MedicinePlanDetail> medicinePlanDetails) { using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { var plan = this.Context.MedicinePlans.FirstOrDefault(x => x.Id == medicinePlan.Id); if (plan == null) { throw new Exception("Dự trù không tồn tại"); } plan.Note = medicinePlan.Note; plan.Status = MedicinePlaningStatus.ReEdited; plan.SetInfo(true); var detailList = this.Context.MedicinePlanDetails.Where(x => x.PlanId == plan.Id).ToList(); foreach (var detail in medicinePlanDetails) { foreach (var original in detailList) { if (original.Id != detail.Id) { continue; } original.Required = detail.Required; original.SetInfo(true); break; } } this.Context.SaveChanges(); scope.Complete(); } }
public void Update(MedicinePlan medicinePlan) { try { var oldMedicinePlan = this.Context.MedicinePlans.FirstOrDefault(x => x.Id == medicinePlan.Id); if (oldMedicinePlan == null) { return; } oldMedicinePlan.Year = medicinePlan.Year; oldMedicinePlan.Month = medicinePlan.Month; oldMedicinePlan.Date = medicinePlan.Date; oldMedicinePlan.ClinicId = medicinePlan.ClinicId; oldMedicinePlan.ApproveId = medicinePlan.ApproveId; oldMedicinePlan.Status = medicinePlan.Status; oldMedicinePlan.Note = medicinePlan.Note; oldMedicinePlan.LastUpdatedUser = AppContext.LoggedInUser.Id; oldMedicinePlan.LastUpdatedDate = DateTime.Now; oldMedicinePlan.Version++; this.Context.SaveChanges(); } catch (Exception ex) { throw; } }
public void Insert(MedicinePlan MedicinePlan) { MedicinePlan.CreatedDate = DateTime.Now; MedicinePlan.CreatedUser = AppContext.LoggedInUser.Id; MedicinePlan.LastUpdatedDate = DateTime.Now; MedicinePlan.LastUpdatedUser = AppContext.LoggedInUser.Id; MedicinePlan.Version = 0; this.Context.MedicinePlans.Add(MedicinePlan); this.Context.SaveChanges(); }
public void Insert(MedicinePlan medicinePlan, List <MedicinePlanDetail> medicinePlanDetails) { using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { medicinePlan.SetInfo(false); this.Context.MedicinePlans.Add(medicinePlan); this.Context.SaveChanges(); foreach (var detail in medicinePlanDetails) { detail.PlanId = medicinePlan.Id; detail.SetInfo(false); this.Context.MedicinePlanDetails.Add(detail); } this.Context.SaveChanges(); scope.Complete(); } }