示例#1
0
        public int Create(FormDto form)
        {
            var documentNo = GenerateDocumentNo(form);
            var model      = new PurchasingMemoDetailTextileModel(form.Date, form.Division.Id, form.Division.Code, form.Division.Name, form.Currency.Id, form.Currency.Code, form.Currency.Rate, form.SupplierIsImport, form.Remark, form.Type, documentNo);

            EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent);
            _dbContext.PurchasingMemoDetailTextiles.Add(model);
            _dbContext.SaveChanges();

            if (form.Type == PurchasingMemoType.Disposition)
            {
                foreach (var item in form.Items)
                {
                    var itemModel = new PurchasingMemoDetailTextileItemModel(item.Disposition.Id, item.Disposition.DocumentNo, item.Disposition.Date, model.Id);
                    EntityExtension.FlagForCreate(itemModel, _identityService.Username, UserAgent);
                    _dbContext.PurchasingMemoDetailTextileItems.Add(itemModel);
                    _dbContext.SaveChanges();

                    foreach (var detail in item.Disposition.Details)
                    {
                        var detailModel = new PurchasingMemoDetailTextileDetailModel(model.Id, itemModel.Id, detail.Expenditure.Id, detail.Expenditure.DocumentNo, detail.Expenditure.Date, detail.Supplier.Id, detail.Supplier.Code, detail.Supplier.Name, detail.Remark, detail.UnitPaymentOrder.Id, detail.UnitPaymentOrder.UnitPaymentOrderNo, detail.UnitPaymentOrder.UnitPaymentOrderDate, detail.PurchaseAmountCurrency, detail.PurchaseAmount, detail.PaymentAmountCurrency, detail.PaymentAmount);
                        EntityExtension.FlagForCreate(detailModel, _identityService.Username, UserAgent);
                        _dbContext.PurchasingMemoDetailTextileDetails.Add(detailModel);
                        _dbContext.SaveChanges();

                        _creditorAccountService.CreateFromPurchasingMemoTextile(new CreditorAccountPurchasingMemoTextileFormDto(detail.UnitPaymentOrder.UnitPaymentOrderNo, model.Id, model.DocumentNo, detail.PaymentAmount, form.Date));

                        foreach (var unitReceiptNote in detail.UnitReceiptNotes)
                        {
                            var unitReceiptNoteModel = new PurchasingMemoDetailTextileUnitReceiptNoteModel(model.Id, itemModel.Id, detailModel.Id, unitReceiptNote.Id, unitReceiptNote.UnitReceiptNoteNo, unitReceiptNote.UnitReceiptNoteDate);
                            EntityExtension.FlagForCreate(unitReceiptNoteModel, _identityService.Username, UserAgent);
                            _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Add(unitReceiptNoteModel);
                            _dbContext.SaveChanges();
                        }
                    }
                }
            }
            else
            {
                foreach (var detail in form.Details)
                {
                    var detailModel = new PurchasingMemoDetailTextileDetailModel(model.Id, 0, detail.Expenditure.Id, detail.Expenditure.DocumentNo, detail.Expenditure.Date, detail.Supplier.Id, detail.Supplier.Code, detail.Supplier.Name, detail.Remark, detail.UnitPaymentOrder.Id, detail.UnitPaymentOrder.UnitPaymentOrderNo, detail.UnitPaymentOrder.UnitPaymentOrderDate, detail.PurchaseAmountCurrency, detail.PurchaseAmount, detail.PaymentAmountCurrency, detail.PaymentAmount);
                    EntityExtension.FlagForCreate(detailModel, _identityService.Username, UserAgent);
                    _dbContext.PurchasingMemoDetailTextileDetails.Add(detailModel);
                    _dbContext.SaveChanges();

                    _creditorAccountService.CreateFromPurchasingMemoTextile(new CreditorAccountPurchasingMemoTextileFormDto(detail.UnitPaymentOrder.UnitPaymentOrderNo, model.Id, model.DocumentNo, detail.PaymentAmount, form.Date));

                    foreach (var unitReceiptNote in detail.UnitReceiptNotes)
                    {
                        var unitReceiptNoteModel = new PurchasingMemoDetailTextileUnitReceiptNoteModel(model.Id, 0, detailModel.Id, unitReceiptNote.Id, unitReceiptNote.UnitReceiptNoteNo, unitReceiptNote.UnitReceiptNoteDate);
                        EntityExtension.FlagForCreate(unitReceiptNoteModel, _identityService.Username, UserAgent);
                        _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Add(unitReceiptNoteModel);
                        _dbContext.SaveChanges();
                    }
                }
            }

            return(model.Id);
        }
示例#2
0
        public int Update(int id, FormDto form)
        {
            var updatedId = 0;
            var model     = _dbContext.PurchasingMemoDetailTextiles.FirstOrDefault(entity => entity.Id == id);

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

                var items            = _dbContext.PurchasingMemoDetailTextileItems.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id).ToList();
                var details          = _dbContext.PurchasingMemoDetailTextileDetails.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id).ToList();
                var unitReceiptNotes = _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Where(entity => entity.PurchasingMemoDetailTextileId == model.Id).ToList();

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

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

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

                _dbContext.SaveChanges();

                if (form.Type == PurchasingMemoType.Disposition)
                {
                    foreach (var item in form.Items)
                    {
                        var itemModel = new PurchasingMemoDetailTextileItemModel(item.Disposition.Id, item.Disposition.DocumentNo, item.Disposition.Date, model.Id);
                        EntityExtension.FlagForCreate(itemModel, _identityService.Username, UserAgent);
                        _dbContext.PurchasingMemoDetailTextileItems.Add(itemModel);
                        _dbContext.SaveChanges();

                        foreach (var detail in item.Disposition.Details)
                        {
                            var detailModel = new PurchasingMemoDetailTextileDetailModel(model.Id, itemModel.Id, detail.Expenditure.Id, detail.Expenditure.DocumentNo, detail.Expenditure.Date, detail.Supplier.Id, detail.Supplier.Code, detail.Supplier.Name, detail.Remark, detail.UnitPaymentOder.Id, detail.UnitPaymentOder.UnitPaymentOrderNo, detail.UnitPaymentOder.UnitPaymentOrderDate, detail.PaymentAmountCurrency, detail.PurchaseAmount, detail.PaymentAmount, detail.PaymentAmountCurrency);
                            EntityExtension.FlagForCreate(detailModel, _identityService.Username, UserAgent);
                            _dbContext.PurchasingMemoDetailTextileDetails.Add(detailModel);
                            _dbContext.SaveChanges();

                            foreach (var unitReceiptNote in detail.UnitReceiptNotes)
                            {
                                var unitReceiptNoteModel = new PurchasingMemoDetailTextileUnitReceiptNoteModel(model.Id, itemModel.Id, detailModel.Id, unitReceiptNote.Id, unitReceiptNote.UnitReceiptNoteNo, unitReceiptNote.UnitReceiptNoteDate);
                                EntityExtension.FlagForCreate(unitReceiptNoteModel, _identityService.Username, UserAgent);
                                _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Add(unitReceiptNoteModel);
                                _dbContext.SaveChanges();
                            }
                        }
                    }
                }
                else
                {
                    foreach (var detail in form.Details)
                    {
                        var detailModel = new PurchasingMemoDetailTextileDetailModel(model.Id, 0, detail.Expenditure.Id, detail.Expenditure.DocumentNo, detail.Expenditure.Date, detail.Supplier.Id, detail.Supplier.Code, detail.Supplier.Name, detail.Remark, detail.UnitPaymentOder.Id, detail.UnitPaymentOder.UnitPaymentOrderNo, detail.UnitPaymentOder.UnitPaymentOrderDate, detail.PaymentAmountCurrency, detail.PurchaseAmount, detail.PaymentAmount, detail.PaymentAmountCurrency);
                        EntityExtension.FlagForCreate(detailModel, _identityService.Username, UserAgent);
                        _dbContext.PurchasingMemoDetailTextileDetails.Add(detailModel);
                        _dbContext.SaveChanges();

                        foreach (var unitReceiptNote in detail.UnitReceiptNotes)
                        {
                            var unitReceiptNoteModel = new PurchasingMemoDetailTextileUnitReceiptNoteModel(model.Id, 0, detailModel.Id, unitReceiptNote.Id, unitReceiptNote.UnitReceiptNoteNo, unitReceiptNote.UnitReceiptNoteDate);
                            EntityExtension.FlagForCreate(unitReceiptNoteModel, _identityService.Username, UserAgent);
                            _dbContext.PurchasingMemoDetailTextileUnitReceiptNotes.Add(unitReceiptNoteModel);
                            _dbContext.SaveChanges();
                        }
                    }
                }

                updatedId = model.Id;
            }

            return(updatedId);
        }