Esempio n. 1
0
        public async Task <int> Update(int id, BookingOrder model)
        {
            Boolean hasBlockingPlan = false;

            try
            {
                if (model.DetailConfirms.Count != 0)
                {
                    // Before Update Check if Booking Order Have Blocking Plan ?
                    hasBlockingPlan = await BlockingPlanLogic.UpdateModelStatus(id, BlockingPlanStatus.CHANGED);

                    // IF hasBlockingPlan  = True
                    if (hasBlockingPlan)
                    {
                        model.IsModified = true;
                    }
                }

                BookingOrderLogic.UpdateModel(id, model);
                return(await DbContext.SaveChangesAsync());
            }
            catch (Exception Ex)
            {
                throw new Exception($"Terjadi Kesalahan Update Booking Order, dengan Kesalahan Sebagai Berikut:  {Ex.ToString()}");
            }
        }
        public async Task <int> Update(int id, BlockingPlan model)
        {
            //BlockingPlanLogic.UpdateModel(id, model);

            #region BookingOrderUpdate
            BookingOrderLogic.UpdateModel(model.BookingOrder.Id, model.BookingOrder);

            //EntityExtension.FlagForUpdate(model.BookingOrder, IdentityService.Username, "masterplan-service");
            //_BookingOrderDbSet.Update(model.BookingOrder);
            #endregion

            #region Looping
            List <int> itemIds = await _BPWorkSchedulesDbSet
                                 .Where(w => w.BlockingPlanId.Equals(id) && !w.IsDeleted)
                                 .Select(s => s.Id).ToListAsync();

            int confirmedItems = 0;
            foreach (var itemId in itemIds)
            {
                var item = model.WorkSchedules.FirstOrDefault(f => f.Id.Equals(itemId));
                if (item == null)
                {
                    var itemToDelete = await _BPWorkSchedulesDbSet
                                       .FirstOrDefaultAsync(f => f.Id.Equals(itemId));

                    _BlockingPlanWorkScheduleLogic.UpdateModel(itemToDelete.Id, itemToDelete);
                    //EntityExtension.FlagForDelete(itemToDelete, IdentityService.Username, "masterplan-service");
                    //_BPWorkSchedulesDbSet.Update(itemToDelete);
                }
                else
                {
                    if (item.isConfirmed)
                    {
                        confirmedItems++;
                    }

                    _BlockingPlanWorkScheduleLogic.UpdateModel(item.Id, item);
                    //EntityExtension.FlagForUpdate(item, IdentityService.Username, "masterplan-service");
                    //_BPWorkSchedulesDbSet.Update(item);
                }
            }

            foreach (var item in model.WorkSchedules)
            {
                if (item.Id <= 0)
                {
                    _BlockingPlanWorkScheduleLogic.CreateModel(item);
                    //EntityExtension.FlagForCreate(item, IdentityService.Username, "masterplan-service");
                    //_BPWorkSchedulesDbSet.Add(item);
                }
            }
            #endregion

            #region Update Status BlockingPlan
            if (confirmedItems == model.WorkSchedules.Count)
            {
                if (confirmedItems == 0)
                {
                    model.Status = BlockingPlanStatus.BOOKING;
                }
                else
                {
                    model.Status = BlockingPlanStatus.FULL_CONFIRMED;
                }
            }
            else if (confirmedItems == 0)
            {
                model.Status = BlockingPlanStatus.BOOKING;
            }
            else
            {
                model.Status = BlockingPlanStatus.HALF_CONFIRMED;
            }

            if (model.IsModified == false || model.IsModified == null)
            {
                model.IsModified = true;
            }
            #endregion

            #region WeeklyPlanUpdate
            //await _weeklyPlanLogic.DeleteByWeeklyplanItemByIdAndWeekId(workschedule);

            var WeeklyPlanBeforeDetele = _BlockingPlanWorkScheduleLogic.GetBlockingPlanWorkScheduleIds(id);
            var WeeklyPlanAfterDelete  = model.WorkSchedules;

            #region Hapus Weekly

            if (WeeklyPlanBeforeDetele.Count > WeeklyPlanAfterDelete.Count())
            {
                if (WeeklyPlanAfterDelete.Count == 0)
                {
                    var workscheduleHapus = _BPWorkSchedulesDbSet.Where(c => c.BlockingPlanId == id).ToList();
                    foreach (var item in workscheduleHapus)
                    {
                        await _weeklyPlanLogic.DeleteByWeeklyplanItemByIdAndWeekId(item);
                    }
                }
                else
                {
                    var workscheduleAll = _BPWorkSchedulesDbSet.Where(c => c.BlockingPlanId == id).ToList();
                    foreach (var beforeDelete in workscheduleAll)
                    {
                        foreach (var afterDelete in WeeklyPlanAfterDelete)
                        {
                            if (beforeDelete.Id == afterDelete.Id)
                            {
                            }
                            else
                            {
                                await _weeklyPlanLogic.DeleteByWeeklyplanItemByIdAndWeekId(beforeDelete);
                            }
                        }
                    }
                }
            }
            #endregion

            #region Tambah Weekly
            else
            {
                foreach (var workschedule in model.WorkSchedules)
                {
                    await _weeklyPlanLogic.UpdateByWeeklyplanItemByIdAndWeekId(workschedule);
                }
            }
            #endregion

            #endregion

            #region BlockingPlanUpdate
            BlockingPlanLogic.UpdateModel(model.Id, model);

            //EntityExtension.FlagForUpdate(model, IdentityService.Username, "masterplan-service");
            //DbSet.Update(model);
            #endregion

            return(await DbContext.SaveChangesAsync());
        }
Esempio n. 3
0
 public async Task <int> Update(int id, BookingOrder model)
 {
     BookingOrderLogic.UpdateModel(id, model);
     return(await DbContext.SaveChangesAsync());
 }