public async Task DeleteByWeeklyplanItemByIdAndWeekId(BlockingPlanWorkSchedule workSchedule) { var query = await DbSet.Include(weeklyplanItem => weeklyplanItem.Items) .Where(weeklyplan => weeklyplan.Id == workSchedule.YearId) .FirstOrDefaultAsync(); foreach (var weeklyplanItem in query.Items) { if (weeklyplanItem.Id == workSchedule.WeekId) { weeklyplanItem.UsedEh = weeklyplanItem.UsedEh - workSchedule.EH_Booking; weeklyplanItem.RemainingEh = weeklyplanItem.EhTotal - weeklyplanItem.UsedEh; } } UpdateModel(query.Id, query); }
public override async void UpdateModel(int id, BlockingPlan model) { try { if (model.WorkSchedules != null) { HashSet <int> detailIds = BlockingPlanWorkScheduleLogic.GetBlockingPlanWorkScheduleIds(id); int countConfirmed = 0; #region Looping Detail Blocking Plan Work Schedule Logic foreach (int detailId in detailIds) { BlockingPlanWorkSchedule detail = model.WorkSchedules.FirstOrDefault(prop => prop.Id.Equals(detailId)); if (detail == null) { await BlockingPlanWorkScheduleLogic.DeleteModel(detailId); } else { if (detail.isConfirmed == true) { countConfirmed++; } BlockingPlanWorkScheduleLogic.UpdateModel(detailId, detail); } } #endregion #region Looping Item in Model WorkSchedules foreach (BlockingPlanWorkSchedule item in model.WorkSchedules) { if (item.Id == 0) { BlockingPlanWorkScheduleLogic.CreateModel(item); } } #endregion #region Set Status Blocking Plan Sewing (FULL CONFIRMED, BOOKING, HALF_CONFIRMED) if (countConfirmed == model.WorkSchedules.Count) { if (countConfirmed == 0) { model.Status = BlockingPlanStatus.BOOKING; } else { model.Status = BlockingPlanStatus.FULL_CONFIRMED; } } else if (countConfirmed == 0) { model.Status = BlockingPlanStatus.BOOKING; } else { model.Status = BlockingPlanStatus.HALF_CONFIRMED; } #endregion if (model.IsModified == false || model.IsModified == null) { model.IsModified = true; } // #region UpdateBookingOrderDetailConfirm // foreach (var item in model.BookingOrder) // { // if (model.IsModified == false || model.IsModified == null) // { // model.IsModified = true; // base.UpdateModel(id, model); // } //// _blockingPlans.Add(item); // } // base.UpdateModel(id, model); // await DbContext.SaveChangesAsync(); // #endregion BookingOrderDetailLogic.UpdateBookingOrderDetailConfirm(model.BookingOrderId); base.UpdateModel(id, model); } } catch (Exception Ex) { throw new Exception(Ex.ToString()); } }