Exemple #1
0
        public Task <int> DeleteAsync(int id)
        {
            var model = _dbContext.VbRequests.Include(en => en.VbRequestDetail).Where(entity => entity.Id == id).FirstOrDefault();

            //var modeldetail = _dbContext.VbRequestsDetails.Where(entity => entity.VBId == id).FirstOrDefault();

            if (model != null)
            {
                EntityExtension.FlagForDelete(model, _identityService.Username, UserAgent);

                foreach (var item in model.VbRequestDetail)
                {
                    EntityExtension.FlagForDelete(item, _identityService.Username, UserAgent);
                }

                _dbContext.VbRequests.Update(model);
            }

            //foreach (var itm1 in model.VbRequestDetail)
            //{
            //    var updateModel = new POExternalUpdateModel()
            //    {
            //        IsCreateOnVBRequest = false
            //    };

            //    UpdateToPOExternal(itm1.PONo.ToString(), updateModel);
            //}

            return(_dbContext.SaveChangesAsync());
        }
Exemple #2
0
        public override async Task UpdateModelAsync(int id, PackingReceiptModel model)
        {
            if (model.Items != null)
            {
                HashSet <int> ItemId = dbSetItem.Where(d => d.PackingReceiptId == model.Id).Select(d => d.Id).ToHashSet();;
                foreach (var itemId in ItemId)
                {
                    PackingReceiptItem data = model.Items.FirstOrDefault(prop => prop.Id.Equals(itemId));
                    if (data == null)
                    {
                        EntityExtension.FlagForDelete(data, IdentityService.Username, UserAgent);
                        dbSetItem.Update(data);
                    }
                    else
                    {
                        EntityExtension.FlagForUpdate(data, IdentityService.Username, UserAgent);
                        dbSetItem.Update(data);
                    }

                    foreach (PackingReceiptItem item in model.Items)
                    {
                        if (item.Id == 0)
                        {
                            EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent);
                            dbSetItem.Add(item);
                        }
                    }
                }
            }

            EntityExtension.FlagForUpdate(model, IdentityService.Username, UserAgent);
            dbSet.Update(model);
            await Task.CompletedTask;
        }
Exemple #3
0
        public int Delete(int id, string username)
        {
            int Deleted = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    var model = this.dbSet
                                .Include(m => m.Items)
                                .SingleOrDefault(m => m.Id == id && !m.IsDeleted);

                    EntityExtension.FlagForDelete(model, username, USER_AGENT);
                    foreach (var item in model.Items)
                    {
                        GarmentUnitReceiptNoteItem garmentUnitReceiptNote = this.dbContext.GarmentUnitReceiptNoteItems.FirstOrDefault(s => s.Id == item.URNItemId);
                        if (garmentUnitReceiptNote != null)
                        {
                            garmentUnitReceiptNote.OrderQuantity = garmentUnitReceiptNote.OrderQuantity - (decimal)item.Quantity;
                        }
                        EntityExtension.FlagForDelete(item, username, USER_AGENT);
                    }

                    Deleted = dbContext.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Deleted);
        }
        public async Task DeleteModel(int id)
        {
            PurchasingDispositionExpeditionModel model = await ReadByIdAsync(id);

            foreach (var item in model.Items)
            {
                EntityExtension.FlagForDelete(item, IdentityService.Username, UserAgent, true);
            }

            List <string> dispoNo = new List <string>();

            dispoNo.Add(model.DispositionNo);

            var dispoCount = this.DbSet.Count(x => x.DispositionNo == model.DispositionNo && x.IsDeleted == false && x.Id != model.Id);

            if (dispoCount > 0)
            {
                UpdateDispositionPosition(dispoNo, ExpeditionPosition.SEND_TO_PURCHASING_DIVISION);
            }
            else
            {
                UpdateDispositionPosition(dispoNo, ExpeditionPosition.PURCHASING_DIVISION);
            }

            EntityExtension.FlagForDelete(model, IdentityService.Username, UserAgent, true);
            DbSet.Update(model);
        }
        public virtual async Task DeleteModel(int id)
        {
            TModel model = await ReadModelById(id);

            EntityExtension.FlagForDelete(model, IdentityService.Username, UserAgent, true);
            DbSet.Update(model);
        }
Exemple #6
0
        //private void AddDetails(int itemId, List<UnitPaymentOrderItemDto> items)
        //{
        //    var models = items.Select(element =>
        //    {
        //        var result = new VBRealizationDocumentUnitCostsItemModel(itemId, element);
        //        EntityExtension.FlagForCreate(result, _identityService.Username, UserAgent);
        //        return result;
        //    }).ToList();

        //    _dbContext.VBRealizationDocumentUnitCostsItems.AddRange(models);
        //    _dbContext.SaveChanges();
        //}

        public int Delete(int id)
        {
            var model = _dbContext.VBRealizationDocuments.FirstOrDefault(entity => entity.Id == id);

            EntityExtension.FlagForDelete(model, _identityService.Username, UserAgent);
            _dbContext.VBRealizationDocuments.Update(model);

            var httpClientService = _serviceProvider.GetService <IHttpClientService>();

            var items = _dbContext.VBRealizationDocumentExpenditureItems.Where(entity => entity.VBRealizationDocumentId == id).ToList();

            items = items.Select(element =>
            {
                element.FlagForDelete(_identityService.Username, UserAgent);
                var result = httpClientService.PutAsync($"{APIEndpoint.Purchasing}vb-request-po-external/spb/{element.UnitPaymentOrderId}?division={model.SuppliantDivisionName}", new StringContent("{}", Encoding.UTF8, General.JsonMediaType)).Result;
                return(element);
            }).ToList();
            _dbContext.VBRealizationDocumentExpenditureItems.UpdateRange(items);

            var vbRequest = _dbContext.VBRequestDocuments.FirstOrDefault(entity => entity.Id == model.VBRequestDocumentId);

            if (vbRequest != null)
            {
                vbRequest.SetIsRealized(false, _identityService.Username, UserAgent);
                _dbContext.VBRequestDocuments.Update(vbRequest);
            }

            _dbContext.SaveChanges();
            return(id);
        }
        public async Task <int> DeleteSingle(int id)
        {
            var costCalculation = await _costCalculationDbSet.FirstOrDefaultAsync(entity => entity.Id == id);

            EntityExtension.FlagForDelete(costCalculation, _identityService.Username, UserAgent);
            _costCalculationDbSet.Update(costCalculation);

            var costCalculationMachines = await _costCalculationMachineDbSet.Where(entity => entity.CostCalculationId == id).ToListAsync();

            costCalculationMachines = costCalculationMachines.Select(entity =>
            {
                EntityExtension.FlagForDelete(entity, _identityService.Username, UserAgent);
                return(entity);
            }).ToList();
            _costCalculationMachineDbSet.UpdateRange(costCalculationMachines);

            var costCalculationChemicals = await _costCalculationChemicalDbSet.Where(entity => entity.CostCalculationId == id).ToListAsync();

            costCalculationChemicals = costCalculationChemicals.Select(entity =>
            {
                EntityExtension.FlagForDelete(entity, _identityService.Username, UserAgent);
                return(entity);
            }).ToList();
            _costCalculationChemicalDbSet.UpdateRange(costCalculationChemicals);

            return(await _dbContext.SaveChangesAsync());
        }
        public override async Task DeleteAsync(long id)
        {
            var model = await ReadByIdAsync(id);

            EntityExtension.FlagForDelete(model, IdentityService.Username, "sales-service", true);
            DbSet.Update(model);
        }
        public Task <int> UpdateAsync(int id, MemoModel model)
        {
            EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);

            var itemIds = _dbContext.MemoItems.Where(entity => entity.MemoId == id).Select(entity => entity.Id).ToList();

            foreach (var itemId in itemIds)
            {
                var item = model.Items.FirstOrDefault(element => element.Id == itemId);
                if (item == null)
                {
                    var itemToDelete = _dbContext.MemoItems.FirstOrDefault(entity => entity.Id == itemId);
                    EntityExtension.FlagForDelete(itemToDelete, _identityService.Username, UserAgent);
                    _dbContext.MemoItems.Update(itemToDelete);
                }
                else
                {
                    EntityExtension.FlagForUpdate(item, _identityService.Username, UserAgent);
                    _dbContext.MemoItems.Update(item);
                }
            }

            foreach (var item in model.Items)
            {
                if (item.Id <= 0)
                {
                    EntityExtension.FlagForCreate(item, _identityService.Username, UserAgent);
                    _dbContext.MemoItems.Add(item);
                }
            }

            _dbContext.Memos.Update(model);

            return(_dbContext.SaveChangesAsync());
        }
Exemple #10
0
        public void Delete(int id)
        {
            var entityToDelete = _dbSet.FirstOrDefault(entity => entity.Id == id);

            EntityExtension.FlagForDelete(entityToDelete, _identityProvider.Username, UserAgent);
            _dbContext.Update(entityToDelete);
        }
        public async Task <int> Delete(int id, string username)
        {
            int Count = 0;

            if (this.dbContext.PPHBankExpenditureNotes.Count(p => p.Id == id && p.IsDeleted == false).Equals(0))
            {
                return(0);
            }

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    PPHBankExpenditureNote PPHBankExpenditureNote = dbContext.PPHBankExpenditureNotes.Single(p => p.Id == id);

                    ICollection <PPHBankExpenditureNoteItem> Items = new List <PPHBankExpenditureNoteItem>(this.dbContext.PPHBankExpenditureNoteItems.Where(p => p.PPHBankExpenditureNoteId.Equals(id)));

                    foreach (PPHBankExpenditureNoteItem item in Items)
                    {
                        EntityExtension.FlagForDelete(item, username, "Facade");
                        this.dbContext.PPHBankExpenditureNoteItems.Update(item);

                        PurchasingDocumentExpedition pde = new PurchasingDocumentExpedition
                        {
                            Id        = item.PurchasingDocumentExpeditionId,
                            IsPaidPPH = false,
                            BankExpenditureNotePPHNo   = null,
                            BankExpenditureNotePPHDate = null
                        };

                        EntityExtension.FlagForUpdate(pde, username, "Facade");
                        //dbContext.Attach(pde);
                        dbContext.Entry(pde).Property(x => x.IsPaidPPH).IsModified = true;
                        dbContext.Entry(pde).Property(x => x.BankExpenditureNotePPHNo).IsModified   = true;
                        dbContext.Entry(pde).Property(x => x.BankExpenditureNotePPHDate).IsModified = true;
                        dbContext.Entry(pde).Property(x => x.LastModifiedAgent).IsModified          = true;
                        dbContext.Entry(pde).Property(x => x.LastModifiedBy).IsModified             = true;
                        dbContext.Entry(pde).Property(x => x.LastModifiedUtc).IsModified            = true;
                    }

                    EntityExtension.FlagForDelete(PPHBankExpenditureNote, username, "Facade");
                    this.dbSet.Update(PPHBankExpenditureNote);
                    Count = await this.dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (DbUpdateConcurrencyException e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Count);
        }
Exemple #12
0
        public async Task DeleteAsync(int id)
        {
            var existingModel = _dbContext.GarmentPurchasingPphBankExpenditureNotes
                                .Include(d => d.Items)
                                .ThenInclude(d => d.GarmentPurchasingPphBankExpenditureNoteInvoices)
                                .Single(x => x.Id == id && !x.IsDeleted);
            var model = await ReadByIdAsync(id);

            foreach (var item in existingModel.Items)
            {
                EntityExtension.FlagForDelete(item, _identityService.Username, UserAgent, true);
            }
            EntityExtension.FlagForDelete(existingModel, _identityService.Username, UserAgent, true);
            _dbContext.GarmentPurchasingPphBankExpenditureNotes.Update(existingModel);

            await _dbContext.SaveChangesAsync();

            ///update ispaidPphStatus
            var listIsPaidStatus = model.PPHBankExpenditureNoteItems.Select(s => new GarmentPurchasingPphBankExpenditureNoteInternNoteIsPaidDto
            {
                InternNoteId = s.INId,
                InternNoteNo = s.INNo,
                IsPphPaid    = false
            }).ToList();

            await UpdateIsPaidPph(listIsPaidStatus);
        }
Exemple #13
0
        public int Update(int id, FormDto form)
        {
            var updatedId = 0;
            var model     = _dbContext.PurchasingMemoTextiles.FirstOrDefault(entity => entity.Id == id);

            if (model != null)
            {
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _dbContext.PurchasingMemoTextiles.Update(model);

                var items = _dbContext.PurchasingMemoTextileItems.Where(entity => entity.PurchasingMemoTextileId == model.Id).ToList();

                items = items.Select(element =>
                {
                    EntityExtension.FlagForDelete(element, _identityService.Username, UserAgent);
                    return(element);
                }).ToList();
                _dbContext.PurchasingMemoTextileItems.UpdateRange(items);

                _dbContext.SaveChanges();

                foreach (var item in form.Items)
                {
                    var itemModel = new PurchasingMemoTextileItemModel(item.ChartOfAccount.Id, item.ChartOfAccount.Code, item.ChartOfAccount.Name, item.DebitAmount, item.CreditAmount, model.Id);
                    EntityExtension.FlagForCreate(itemModel, _identityService.Username, UserAgent);
                    _dbContext.PurchasingMemoTextileItems.Add(itemModel);
                    _dbContext.SaveChanges();
                }

                updatedId = model.Id;
            }

            return(updatedId);
        }
Exemple #14
0
        public override void UpdateAsync(long id, RO_Garment_SizeBreakdown model)
        {
            if (model.RO_Garment_SizeBreakdown_Details != null)
            {
                HashSet <long> detailIds = roGarmentSizeBreakdownDetailLogic.GetIds(id);
                foreach (var itemId in detailIds)
                {
                    RO_Garment_SizeBreakdown_Detail data = model.RO_Garment_SizeBreakdown_Details.FirstOrDefault(prop => prop.Id.Equals(itemId));
                    if (data == null)
                    {
                        RO_Garment_SizeBreakdown_Detail dataItem = DbContext.RO_Garment_SizeBreakdown_Details.FirstOrDefault(prop => prop.Id.Equals(itemId));
                        EntityExtension.FlagForDelete(dataItem, IdentityService.Username, "sales-service");
                        //await roGarmentSizeBreakdownDetailLogic.DeleteAsync(itemId);
                    }
                    else
                    {
                        roGarmentSizeBreakdownDetailLogic.UpdateAsync(itemId, data);
                    }

                    foreach (RO_Garment_SizeBreakdown_Detail item in model.RO_Garment_SizeBreakdown_Details)
                    {
                        if (item.Id == 0)
                        {
                            roGarmentSizeBreakdownDetailLogic.Create(item);
                        }
                    }
                }
            }

            EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service");
            DbSet.Update(model);
        }
        public virtual async Task DeleteAsync(int id)
        {
            TModel model = await ReadByIdAsync(id);

            EntityExtension.FlagForDelete(model, IdentityService.Username, "sales-service", true);
            DbSet.Update(model);
        }
        public async Task <int> UpdateAsync(int id, GarmentFinanceBankCashReceiptDetailLocalModel model)
        {
            GarmentFinanceBankCashReceiptDetailLocalModel exist = _dbContext.GarmentFinanceBankCashReceiptDetailLocals
                                                                  .Include(d => d.Items)
                                                                  .Include(d => d.OtherItems)
                                                                  .Single(dispo => dispo.Id == id && !dispo.IsDeleted);

            foreach (var item in exist.Items)
            {
                GarmentFinanceBankCashReceiptDetailLocalItemModel itemModel = model.Items.FirstOrDefault(prop => prop.Id.Equals(item.Id));

                if (itemModel == null)
                {
                    EntityExtension.FlagForDelete(item, _identityService.Username, UserAgent, true);
                }
                else
                {
                    item.Amount = itemModel.Amount;
                    EntityExtension.FlagForUpdate(item, _identityService.Username, UserAgent);
                }
            }

            foreach (var newItem in model.Items)
            {
                if (newItem.Id == 0)
                {
                    exist.Items.Add(newItem);
                    EntityExtension.FlagForCreate(newItem, _identityService.Username, UserAgent);
                }
            }

            foreach (var otherItem in exist.OtherItems)
            {
                GarmentFinanceBankCashReceiptDetailLocalOtherItemModel itemModel = model.OtherItems.FirstOrDefault(prop => prop.Id.Equals(otherItem.Id));

                if (itemModel == null)
                {
                    EntityExtension.FlagForDelete(otherItem, _identityService.Username, UserAgent, true);
                }
                else
                {
                    otherItem.Amount     = itemModel.Amount;
                    otherItem.TypeAmount = itemModel.TypeAmount;
                    EntityExtension.FlagForUpdate(otherItem, _identityService.Username, UserAgent);
                }
            }

            foreach (var newOtherItem in model.OtherItems)
            {
                if (newOtherItem.Id == 0)
                {
                    exist.OtherItems.Add(newOtherItem);
                    EntityExtension.FlagForCreate(newOtherItem, _identityService.Username, UserAgent);
                }
            }

            EntityExtension.FlagForUpdate(exist, _identityService.Username, UserAgent);

            return(await _dbContext.SaveChangesAsync());
        }
        public override void UpdateAsync(long id, CostCalculationGarment model)
        {
            GeneratePONumbers(model);
            if (model.CostCalculationGarment_Materials != null)
            {
                HashSet <long> detailIds = costCalculationGarmentMaterialLogic.GetCostCalculationIds(id);
                foreach (var itemId in detailIds)
                {
                    CostCalculationGarment_Material data = model.CostCalculationGarment_Materials.FirstOrDefault(prop => prop.Id.Equals(itemId));
                    if (data == null)
                    {
                        CostCalculationGarment_Material dataItem = DbContext.CostCalculationGarment_Materials.FirstOrDefault(prop => prop.Id.Equals(itemId));
                        EntityExtension.FlagForDelete(dataItem, IdentityService.Username, "sales-service");
                        //await costCalculationGarmentMaterialLogic.DeleteAsync(itemId);
                    }
                    else
                    {
                        costCalculationGarmentMaterialLogic.UpdateAsync(itemId, data);
                    }

                    foreach (CostCalculationGarment_Material item in model.CostCalculationGarment_Materials)
                    {
                        if (item.Id <= 0)
                        {
                            costCalculationGarmentMaterialLogic.Create(item);
                        }
                    }
                }
            }

            EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service");
            DbSet.Update(model);
        }
        public async Task <int> DeleteAsync(int id)
        {
            var existingModel = _dbContext.GarmentFinanceBankCashReceiptDetailLocals
                                .Include(d => d.Items)
                                .Include(d => d.OtherItems)
                                .Single(x => x.Id == id && !x.IsDeleted);
            GarmentFinanceBankCashReceiptDetailLocalModel model = await ReadByIdAsync(id);

            foreach (var item in model.Items)
            {
                EntityExtension.FlagForDelete(item, _identityService.Username, UserAgent, true);
            }
            foreach (var otherItem in model.OtherItems)
            {
                EntityExtension.FlagForDelete(otherItem, _identityService.Username, UserAgent, true);
            }

            EntityExtension.FlagForDelete(model, _identityService.Username, UserAgent, true);
            var receipts = await _dbContext.GarmentFinanceBankCashReceipts.FirstOrDefaultAsync(a => a.Id == model.BankCashReceiptId);

            if (receipts != null)
            {
                receipts.IsUsed = false;
            }
            _dbContext.GarmentFinanceBankCashReceiptDetailLocals.Update(model);

            return(await _dbContext.SaveChangesAsync());
        }
Exemple #19
0
        public async Task <int> DeleteAsync(int id)
        {
            var existingModel = DbSet
                                .Include(d => d.Items)
                                .Include(d => d.OtherItems)
                                .Include(m => m.RupiahItems)
                                .Single(o => o.Id == id && !o.IsDeleted);

            GarmentFinanceMemorialDetailModel model = await ReadByIdAsync(id);

            foreach (var item in model.Items)
            {
                EntityExtension.FlagForDelete(item, IdentityService.Username, UserAgent, true);
            }
            foreach (var otherItem in model.OtherItems)
            {
                EntityExtension.FlagForDelete(otherItem, IdentityService.Username, UserAgent, true);
            }
            foreach (var rupiahItem in model.RupiahItems)
            {
                EntityExtension.FlagForDelete(rupiahItem, IdentityService.Username, UserAgent, true);
            }
            EntityExtension.FlagForDelete(model, IdentityService.Username, UserAgent, true);
            var memorial = GarmentFinanceMemorialDbSet.Single(a => a.Id == model.MemorialId);

            memorial.IsUsed = false;
            DbSet.Update(model);
            return(await DbContext.SaveChangesAsync());
        }
        public override async Task DeleteModel(int id)
        {
            BlockingPlan model = await ReadModelById(id);

            var workschedules = model.WorkSchedules;

            foreach (var workschedule in workschedules)
            {
                await WeeklyPlanLogic.DeleteByWeeklyplanItemByIdAndWeekId(workschedule);
            }

            foreach (var item in model.WorkSchedules)
            {
                //EntityExtension.FlagForDelete(item, IdentityService.Username, "masterplan-service");
                await BlockingPlanWorkScheduleLogic.DeleteModel(item.Id);
            }

            BookingOrder bookingOrder = await BookingOrderLogic.ReadModelById(model.BookingOrderId);

            BookingOrderLogic.UpdateModelBlockingPlanId(bookingOrder.Id, bookingOrder, null);

            EntityExtension.FlagForDelete(model, IdentityService.Username, "masterplan-service", true);
            DbSet.Update(model);

            await DbContext.SaveChangesAsync();
        }
Exemple #21
0
        public Task <int> UpdateAsync(int id, ProductPackingInventoryMovementModel model)
        {
            EntityExtension.FlagForDelete(model, _identityProvider.Username, UserAgent);
            _dbContext.ProductPackingInventoryMovements.Update(model);

            return(_dbContext.SaveChangesAsync());
        }
        public Task <int> UpdateAsync(int id, GreigeProductSKUModel model)
        {
            EntityExtension.FlagForDelete(model, _identityProvider.Username, UserAgent);
            _dbContext.GreigeProductSKUs.Update(model);

            return(_dbContext.SaveChangesAsync());
        }
        public int DeleteWithPO(int id)
        {
            var model = _dbContext.VBRequestDocuments.FirstOrDefault(entity => entity.Id == id);

            EntityExtension.FlagForDelete(model, _identityService.Username, UserAgent);
            _dbContext.Update(model);

            var items = _dbContext.VBRequestDocumentItems.Where(entity => entity.VBRequestDocumentId == model.Id).ToList();

            items = items.Select(element =>
            {
                EntityExtension.FlagForDelete(element, _identityService.Username, UserAgent);
                return(element);
            }).ToList();

            var itemIds = items.Select(element => element.Id).ToList();
            var details = _dbContext.VBRequestDocumentEPODetails.Where(entity => itemIds.Contains(entity.VBRequestDocumentItemId)).ToList();

            details = details.Select(element =>
            {
                EntityExtension.FlagForDelete(element, _identityService.Username, UserAgent);
                return(element);
            }).ToList();

            _dbContext.SaveChanges();

            return(model.Id);
        }
        public async Task <int> DeleteAsync(int id)
        {
            var transaction = _context.Database.BeginTransaction();

            try
            {
                var model = await ReadByIdAsync(id);

                EntityExtension.FlagForDelete(model, _identityService.Username, UserAgent);

                foreach (var detail in model.MemoGarmentPurchasingDetails)
                {
                    EntityExtension.FlagForDelete(detail, _identityService.Username, UserAgent);
                }

                _context.Update(model);
                var result = await _context.SaveChangesAsync();

                transaction.Commit();
                return(result);
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
        }
Exemple #25
0
        public async Task <int> Delete(int id)
        {
            int Deleted = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    var garmentUnitDeliveryOrder = dbSet
                                                   .Include(m => m.Items)
                                                   .SingleOrDefault(m => m.Id == id);

                    EntityExtension.FlagForDelete(garmentUnitDeliveryOrder, identityService.Username, USER_AGENT);
                    foreach (var garmentUnitDeliveryOrderItem in garmentUnitDeliveryOrder.Items)
                    {
                        EntityExtension.FlagForDelete(garmentUnitDeliveryOrderItem, identityService.Username, USER_AGENT);

                        GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem = dbContext.GarmentUnitReceiptNoteItems.Single(s => s.Id == garmentUnitDeliveryOrderItem.URNItemId);
                        EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT);
                        garmentUnitReceiptNoteItem.OrderQuantity = garmentUnitReceiptNoteItem.OrderQuantity - (decimal)garmentUnitDeliveryOrderItem.Quantity;
                    }

                    Deleted = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Deleted);
        }
        public async Task <int> Delete(int id)
        {
            var transaction = _context.Database.BeginTransaction();

            try
            {
                var model = await GetSingleById(id);

                if (model == null)
                {
                    throw new Exception("Invalid Id");
                }

                EntityExtension.FlagForDelete(model, _userBy, _userAgent);
                _WebContentDbSet.Update(model);
                var result = await _context.SaveChangesAsync();

                transaction.Commit();

                return(result);
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
        }
        public override async Task DeleteAsync(long id)
        {
            ProductionOrderModel model = await ReadByIdAsync(id);

            foreach (var detail in model.Details)
            {
                await productionOrder_DetailLogic.DeleteAsync(detail.Id);
            }

            foreach (var lampStandards in model.LampStandards)
            {
                await productionOrder_LampStandardLogic.DeleteAsync(lampStandards.Id);
            }


            if (model.RunWidths.Count > 0)
            {
                foreach (var runWidths in model.RunWidths)
                {
                    await productionOrder_RunWidthLogic.DeleteAsync(runWidths.Id);
                }
            }

            EntityExtension.FlagForDelete(model, IdentityService.Username, "sales-service", true);
            DbSet.Update(model);
        }
        public override void UpdateModelAsync(int id, DurationEstimationModel model)
        {
            if (model.Areas != null)
            {
                HashSet <int> areaIds = _DbSetDurationEstimationArea.Where(d => d.DurationEstimationId == id).Select(d => d.Id).ToHashSet();

                foreach (int areaId in areaIds)
                {
                    var area = model.Areas.FirstOrDefault(prop => prop.Id.Equals(areaId));

                    if (area == null)
                    {
                        area = _DbSetDurationEstimationArea.Where(w => w.Id == areaId).FirstOrDefault();
                        EntityExtension.FlagForDelete(area, IdentityService.Username, UserAgent);
                        _DbSetDurationEstimationArea.Update(area);
                    }
                    else
                    {
                        EntityExtension.FlagForUpdate(area, IdentityService.Username, UserAgent);
                        _DbSetDurationEstimationArea.Update(area);
                    }
                }

                foreach (var area in model.Areas)
                {
                    if (area.Id == 0)
                    {
                        EntityExtension.FlagForCreate(area, IdentityService.Username, UserAgent);
                        _DbSetDurationEstimationArea.Add(area);
                    }
                }
            }
            base.UpdateModelAsync(id, model);
        }
Exemple #29
0
        private string DocumentNoGenerator(AccountBankViewModel bank)
        {
            var latestDocumentNo = _dbContext.OthersExpenditureProofDocuments.IgnoreQueryFilters().Where(document => document.DocumentNo.Contains(bank.BankCode)).OrderByDescending(document => document.Id).Select(document => new { document.DocumentNo, document.CreatedUtc }).FirstOrDefault();

            var now    = DateTimeOffset.Now;
            var result = "";

            if (latestDocumentNo == null)
            {
                result = $"{now:yy}{now:MM}{bank.BankCode}K0001";
            }
            else
            {
                if (latestDocumentNo.CreatedUtc.Month != now.Month)
                {
                    result = $"{now:yy}{now:MM}{bank.BankCode}K0001";
                }
                else
                {
                    var numberString = latestDocumentNo.DocumentNo.Split("K").ToList()[1];
                    var number       = int.Parse(numberString) + 1;
                    result = $"{now:yy}{now:MM}{bank.BankCode}K{number.ToString().PadLeft(4, '0')}";
                }
            }

            var model = new OthersExpenditureProofDocumentModel();

            model.DocumentNo = result;
            EntityExtension.FlagForCreate(model, _identityService.Username, "finance-accounting-service");
            EntityExtension.FlagForDelete(model, _identityService.Username, "finance-accounting-service");
            _dbContext.OthersExpenditureProofDocuments.Add(model);
            _dbContext.SaveChanges();

            return(result);
        }
Exemple #30
0
        public async Task <int> Delete(int id)
        {
            int Deleted = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    var dataModel = dbSet.FirstOrDefault(s => s.Id == id);

                    EntityExtension.FlagForDelete(dataModel, identityService.Username, USER_AGENT);

                    var afterDeletedModel = dbContext.GarmentDispositionPurchases.Update(dataModel);
                    Deleted = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Deleted);
        }