private GarmentDebtBalanceModel GenerateDataUtil(FinanceDbContext dbContext) { var model = new GarmentDebtBalanceModel(1, "category", "billsNo", "paymentBills", 1, "deliveryOrderNo", 1, "supplier", 1, "IDR", 1); EntityExtension.FlagForCreate(model, "unit-test", "data-util"); dbContext.GarmentDebtBalances.Add(model); dbContext.SaveChanges(); return(model); }
public async Task UploadData(SODocs data, string username) { foreach (var i in data.Items) { EntityExtension.FlagForCreate(i, username, USER_AGENT); } EntityExtension.FlagForCreate(data, username, USER_AGENT); dbSetSO.Add(data); var result = await dbContext.SaveChangesAsync(); }
public override void CreateModel(MachineStepModel model) { do { model.Code = CodeGenerator.Generate(); }while (DbSet.Any(d => d.Code.Equals(model.Code))); EntityExtension.FlagForCreate(model, IdentityService.Username, UserAgent); base.CreateModel(model); }
public override void Create(RO_Garment_SizeBreakdown model) { foreach (var size in model.RO_Garment_SizeBreakdown_Details) { roGarmentSizeBreakdownDetailLogic.Create(size); } EntityExtension.FlagForCreate(model, IdentityService.Username, "sales-service"); DbSet.Add(model); }
public int Create(FormDto form) { var model = new VBRealizationDocumentModel(); string division = GetDivision(form); var unitCode = GetDocumentUnitCode(division, form.IsInklaring); var existingData = _dbContext.VBRealizationDocuments .Where(a => a.Date.AddHours(_identityService.TimezoneOffset).Month == form.Date.GetValueOrDefault().AddHours(_identityService.TimezoneOffset).Month && a.DocumentNo.StartsWith(unitCode)) .OrderByDescending(s => s.Index) .FirstOrDefault(); var documentNo = GetDocumentNo(form, existingData); var amount = form.Items.Sum(element => { var nominal = element.UnitPaymentOrder.Amount.GetValueOrDefault(); var vatNominal = (decimal)0.0; var incomeTaxNominal = (decimal)0.0; if (element.UnitPaymentOrder.UseVat.GetValueOrDefault()) vatNominal = element.UnitPaymentOrder.Amount.GetValueOrDefault() * (Convert.ToDecimal(element.UnitPaymentOrder.VatTax.Rate)/100); if (element.UnitPaymentOrder.UseIncomeTax.GetValueOrDefault() && element.UnitPaymentOrder.IncomeTaxBy.ToUpper() == "SUPPLIER") incomeTaxNominal = element.UnitPaymentOrder.Amount.GetValueOrDefault() * (decimal)element.UnitPaymentOrder.IncomeTax.Rate.GetValueOrDefault() / 100; return nominal + vatNominal - incomeTaxNominal; }); if (form.Type == "Tanpa Nomor VB") model = new VBRealizationDocumentModel(form.Currency, form.Date, form.SuppliantUnit, documentNo, (decimal)amount, form.Remark); else { var vbRequest = _dbContext.VBRequestDocuments.FirstOrDefault(entity => entity.Id == form.VBRequestDocument.Id.GetValueOrDefault()); if (vbRequest != null) { vbRequest.SetIsRealized(true, _identityService.Username, UserAgent); _dbContext.VBRequestDocuments.Update(vbRequest); } model = new VBRealizationDocumentModel(form.Date, vbRequest, documentNo, (decimal)amount, form.Remark); } EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent); _dbContext.VBRealizationDocuments.Add(model); _dbContext.SaveChanges(); AddItems(model.Id, form.Items, model.SuppliantDivisionName); AddUnitCosts(model.Id, form.Items.SelectMany(element => element.UnitPaymentOrder.UnitCosts).ToList()); _dbContext.SaveChanges(); return model.Id; }
public async Task <int> Create(GarmentInternNote m, bool isImport, string user, int clientTimeZoneOffset = 7) { int Created = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForCreate(m, user, USER_AGENT); m.INNo = await GenerateNo(m, isImport, clientTimeZoneOffset); m.INDate = DateTimeOffset.Now; foreach (var item in m.Items) { GarmentInvoice garmentInvoice = this.dbContext.GarmentInvoices.FirstOrDefault(s => s.Id == item.InvoiceId); if (garmentInvoice != null) { garmentInvoice.HasInternNote = true; } EntityExtension.FlagForCreate(item, user, USER_AGENT); foreach (var detail in item.Details) { GarmentDeliveryOrder garmentDeliveryOrder = this.dbContext.GarmentDeliveryOrders.FirstOrDefault(s => s.Id == detail.DOId); GarmentInternalPurchaseOrder internalPurchaseOrder = this.dbContext.GarmentInternalPurchaseOrders.FirstOrDefault(s => s.RONo.Equals(detail.RONo)); if (internalPurchaseOrder != null) { detail.UnitId = internalPurchaseOrder.UnitId; detail.UnitCode = internalPurchaseOrder.UnitCode; detail.UnitName = internalPurchaseOrder.UnitName; } if (garmentDeliveryOrder != null) { garmentDeliveryOrder.InternNo = m.INNo; } EntityExtension.FlagForCreate(detail, user, USER_AGENT); } } this.dbSet.Add(m); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public async Task <int> Create(UnitPaymentCorrectionNote m, string user, int clientTimeZoneOffset = 7) { int Created = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForCreate(m, user, USER_AGENT); var supplier = GetSupplier(m.SupplierId); var supplierImport = false; m.SupplierNpwp = null; if (supplier != null) { m.SupplierNpwp = supplier.npwp; supplierImport = supplier.import; } m.UPCNo = await GenerateNo(m, clientTimeZoneOffset, supplierImport, m.DivisionName); if (m.useVat == true) { m.ReturNoteNo = await GeneratePONo(m, clientTimeZoneOffset); } UnitPaymentOrder unitPaymentOrder = this.dbContext.UnitPaymentOrders.Where(s => s.Id == m.UPOId).Include(p => p.Items).ThenInclude(i => i.Details).FirstOrDefault(); unitPaymentOrder.IsCorrection = true; foreach (var item in m.Items) { EntityExtension.FlagForCreate(item, user, USER_AGENT); foreach (var itemSpb in unitPaymentOrder.Items) { foreach (var detailSpb in itemSpb.Details) { if (item.UPODetailId == detailSpb.Id) { detailSpb.QuantityCorrection = detailSpb.QuantityCorrection - item.Quantity; } } } } this.dbSet.Add(m); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public async Task <int> CreateAttachment(long activityId, List <ActivityAttachment> attachments) { foreach (ActivityAttachment attachment in attachments) { attachment.ActivityId = activityId; EntityExtension.FlagForCreate(attachment, IdentityService.Username, "deal-tracking-service"); DbContext.DealTrackingActivityAttachments.Add(attachment); } return(await DbContext.SaveChangesAsync()); }
public async Task <int> UpdateAsync(int id, MemoGarmentPurchasingModel model) { var transaction = _context.Database.BeginTransaction(); try { var modelToUpdate = await ReadByIdAsync(id); modelToUpdate.Remarks = model.Remarks; EntityExtension.FlagForUpdate(modelToUpdate, _identityService.Username, UserAgent); _context.Update(modelToUpdate); var modelIds = model.MemoGarmentPurchasingDetails.Select(x => x.Id).ToList(); var detailToUpdate = modelToUpdate.MemoGarmentPurchasingDetails.Select(x => { var dat = model.MemoGarmentPurchasingDetails.Where(y => y.Id.Equals(x.Id)).FirstOrDefault(); if (dat != null) { x.COAId = dat.COAId; x.COAName = dat.COAName; x.COANo = dat.COANo; x.DebitNominal = dat.DebitNominal; x.CreditNominal = dat.CreditNominal; EntityExtension.FlagForUpdate(x, _identityService.Username, UserAgent); return(x); } EntityExtension.FlagForDelete(x, _identityService.Username, UserAgent); return(x); }); _context.MemoGarmentPurchasingDetails.UpdateRange(detailToUpdate); if (model.MemoGarmentPurchasingDetails.Any(x => x.Id < 1)) { var detailToCreate = model.MemoGarmentPurchasingDetails.Where(x => x.Id < 1).Select(x => { x.MemoId = modelToUpdate.Id; EntityExtension.FlagForCreate(x, _identityService.Username, UserAgent); return(x); }); _context.MemoGarmentPurchasingDetails.AddRange(detailToCreate); } var result = await _context.SaveChangesAsync(); transaction.Commit(); return(result); } catch (Exception e) { transaction.Rollback(); throw e; } }
public async Task <int> Create(GarmentBeacukai model, string username, int clientTimeZoneOffset = 7) { int Created = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForCreate(model, username, USER_AGENT); foreach (GarmentBeacukaiItem item in model.Items) { GarmentDeliveryOrder deliveryOrder = dbSetDeliveryOrder.Include(m => m.Items) .ThenInclude(i => i.Details).FirstOrDefault(s => s.Id == item.GarmentDOId); if (deliveryOrder != null) { if (model.BillNo == "" | model.BillNo == null) { deliveryOrder.BillNo = GenerateBillNo(); } else { deliveryOrder.BillNo = model.BillNo; } deliveryOrder.PaymentBill = GeneratePaymentBillNo(); deliveryOrder.CustomsId = model.Id; double qty = 0; foreach (var deliveryOrderItem in deliveryOrder.Items) { foreach (var detail in deliveryOrderItem.Details) { qty += detail.DOQuantity; } } item.TotalAmount = Convert.ToDecimal(deliveryOrder.TotalAmount); item.TotalQty = qty; EntityExtension.FlagForCreate(item, username, USER_AGENT); } } this.dbSet.Add(model); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public void CreateModel(MemoDetailGarmentPurchasingModel model) { EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent); foreach (var item in model.MemoDetailGarmentPurchasingDetail) { EntityExtension.FlagForCreate(item, _identityService.Username, UserAgent); } DbSet.Add(model); }
public async Task <int> CreateAsync(Role model) { EntityExtension.FlagForCreate(model, IdentityService.Username, UserAgent); foreach (var item in model.Permissions) { EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent); } DbSet.Add(model); return(await DbContext.SaveChangesAsync()); }
public async Task <int> Create(GarmentUnitDeliveryOrder garmentUnitDeliveryOrder) { int Created = 0; using (var transaction = this.dbContext.Database.BeginTransaction()) { try { garmentUnitDeliveryOrder.Items = garmentUnitDeliveryOrder.Items.Where(x => x.IsSave).ToList(); EntityExtension.FlagForCreate(garmentUnitDeliveryOrder, identityService.Username, USER_AGENT); garmentUnitDeliveryOrder.UnitDONo = await GenerateNo(garmentUnitDeliveryOrder); foreach (var garmentUnitDeliveryOrderItem in garmentUnitDeliveryOrder.Items) { EntityExtension.FlagForCreate(garmentUnitDeliveryOrderItem, identityService.Username, USER_AGENT); // GarmentDOItems GarmentDOItems garmentDOItems = dbSetGarmentDOItems.Single(w => w.Id == garmentUnitDeliveryOrderItem.DOItemsId); EntityExtension.FlagForUpdate(garmentDOItems, identityService.Username, USER_AGENT); garmentDOItems.RemainingQuantity = garmentDOItems.RemainingQuantity - (decimal)garmentUnitDeliveryOrderItem.Quantity; garmentUnitDeliveryOrderItem.DOCurrencyRate = garmentDOItems.DOCurrencyRate; if (garmentUnitDeliveryOrderItem.DOCurrencyRate == 0) { throw new Exception("garmentUnitDeliveryOrderItem.DOCurrencyRate tidak boleh 0"); } GarmentUnitReceiptNote garmentUnitReceiptNote = dbContext.GarmentUnitReceiptNotes.IgnoreQueryFilters().Single(s => s.Id == garmentUnitDeliveryOrderItem.URNId); garmentUnitReceiptNote.IsUnitDO = true; GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem = dbContext.GarmentUnitReceiptNoteItems.IgnoreQueryFilters().Single(s => s.Id == garmentUnitDeliveryOrderItem.URNItemId); garmentUnitReceiptNoteItem.OrderQuantity = garmentUnitReceiptNoteItem.OrderQuantity + (decimal)garmentUnitDeliveryOrderItem.Quantity; EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT); } dbSet.Add(garmentUnitDeliveryOrder); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public override void UpdateAsync(long id, GarmentSewingBlockingPlan newModel) { var model = DbSet.AsNoTracking().Include(d => d.Items).FirstOrDefault(d => d.Id == id); if (model.Status == "Booking Ada Perubahan") { newModel.Status = "Booking"; } foreach (var item in model.Items) { GarmentWeeklyPlanItem week = DbContext.GarmentWeeklyPlanItems.FirstOrDefault(a => a.Id == item.WeeklyPlanItemId); week.UsedEH -= (int)item.EHBooking; week.RemainingEH += (int)item.EHBooking; } foreach (var newPlan in newModel.Items) { GarmentWeeklyPlanItem week = DbContext.GarmentWeeklyPlanItems.FirstOrDefault(a => a.Id == newPlan.WeeklyPlanItemId); //var oldItem = model.Items.FirstOrDefault(i => i.Id == newPlan.Id); if (newPlan.Id == 0) { week.UsedEH += (int)newPlan.EHBooking; week.RemainingEH -= (int)newPlan.EHBooking; EntityExtension.FlagForCreate(newPlan, IdentityService.Username, "sales-service"); } else { week.UsedEH += (int)newPlan.EHBooking; week.RemainingEH -= (int)newPlan.EHBooking; EntityExtension.FlagForUpdate(newPlan, IdentityService.Username, "sales-service"); } } DbSet.Update(newModel); foreach (var oldItem in model.Items) { var newItem = newModel.Items.FirstOrDefault(i => i.Id == oldItem.Id); if (newItem == null) { EntityExtension.FlagForDelete(oldItem, IdentityService.Username, "sales-service"); DbContext.GarmentSewingBlockingPlanItems.Update(oldItem); } } //DbSet.Update(model); EntityExtension.FlagForUpdate(newModel, IdentityService.Username, "sales-service"); }
public int CreateFromCustoms(CustomsFormDto form) { var model = new GarmentDebtBalanceModel(form.PurchasingCategoryId, form.PurchasingCategoryName, form.BillsNo, form.PaymentBills, form.GarmentDeliveryOrderId, form.GarmentDeliveryOrderNo, form.SupplierId, form.SupplierCode, form.SupplierName, form.SupplierIsImport, form.CurrencyId, form.CurrencyCode, form.CurrencyRate, form.ProductNames, form.ArrivalDate, form.DPPAmount, form.CurrencyDPPAmount, form.PaymentType); EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent); _dbContext.GarmentDebtBalances.Add(model); _dbContext.SaveChanges(); return(model.Id); }
public override void Create(GarmentBookingOrder model) { GenerateBookingOrderNo(model); if (model.Items.Count > 0) { model.HadConfirmed = true; } EntityExtension.FlagForCreate(model, IdentityService.Username, "sales-service"); DbSet.Add(model); }
public override void CreateModel(InstructionModel model) { foreach (var step in model.Steps) { EntityExtension.FlagForCreate(step, IdentityService.Username, UserAgent); foreach (var stepIndicator in step.StepIndicators) { EntityExtension.FlagForCreate(stepIndicator, IdentityService.Username, UserAgent); } } base.CreateModel(model); }
public override void Create(FinishingPrintingSalesContractModel model) { foreach (var detail in model.Details) { FinishingPrintingSalesContractDetailLogic.Create(detail); //EntityExtension.FlagForCreate(detail, IdentityService.Username, "sales-service"); } EntityExtension.FlagForCreate(model, IdentityService.Username, Agent); DbSet.Add(model); UpdateFPCostCalculationIsSCCreated(model, true); }
public async Task <int> Create(BankExpenditureNoteModel model, string username) { int Created = 0; using (var transaction = dbContext.Database.BeginTransaction()) { try { EntityExtension.FlagForCreate(model, username, USER_AGENT); model.DocumentNo = await bankDocumentNumberGenerator.GenerateDocumentNumber("K", model.BankCode, username); foreach (var detail in model.Details) { EntityExtension.FlagForCreate(detail, username, USER_AGENT); PurchasingDocumentExpedition pde = new PurchasingDocumentExpedition { Id = (int)detail.UnitPaymentOrderId, IsPaid = true, BankExpenditureNoteNo = model.DocumentNo, BankExpenditureNoteDate = model.Date }; EntityExtension.FlagForUpdate(pde, username, USER_AGENT); dbContext.Attach(pde); dbContext.Entry(pde).Property(x => x.IsPaid).IsModified = true; dbContext.Entry(pde).Property(x => x.BankExpenditureNoteNo).IsModified = true; dbContext.Entry(pde).Property(x => x.BankExpenditureNoteDate).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; foreach (var item in detail.Items) { EntityExtension.FlagForCreate(item, username, USER_AGENT); } } dbSet.Add(model); Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public async Task <int> CreateAsync(GarmentInvoicePaymentModel model) { model.InvoicePaymentNo = await GenerateNo(model, 7); EntityExtension.FlagForCreate(model, IdentityService.Username, UserAgent); foreach (var item in model.Items) { EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent); } DbSet.Add(model); return(await DbContext.SaveChangesAsync()); }
public override void CreateModel(DyestuffChemicalUsageReceiptModel model) { foreach (var item in model.DyestuffChemicalUsageReceiptItems) { EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent); foreach (var detail in item.DyestuffChemicalUsageReceiptItemDetails) { EntityExtension.FlagForCreate(detail, IdentityService.Username, UserAgent); } } base.CreateModel(model); }
public override void Create(CostCalculationGarment model) { GeneratePONumbers(model); foreach (var detail in model.CostCalculationGarment_Materials) { costCalculationGarmentMaterialLogic.Create(detail); //EntityExtension.FlagForCreate(detail, IdentityService.Username, "sales-service"); } EntityExtension.FlagForCreate(model, IdentityService.Username, "sales-service"); DbSet.Add(model); }
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 Create(FormDto form) { var model = new VBRealizationDocumentModel(); var existingData = _dbContext.VBRealizationDocuments.Where(a => a.Date.AddHours(_identityService.TimezoneOffset).Month == form.Date.GetValueOrDefault().AddHours(_identityService.TimezoneOffset).Month).OrderByDescending(s => s.Index).FirstOrDefault(); var documentNo = GetDocumentNo(form, existingData); var amount = form.Items.Sum(element => { var nominal = element.UnitPaymentOrder.Amount.GetValueOrDefault(); if (element.UnitPaymentOrder.UseVat.GetValueOrDefault()) { nominal += element.UnitPaymentOrder.Amount.GetValueOrDefault() * (decimal)0.1; } if (element.UnitPaymentOrder.UseIncomeTax.GetValueOrDefault() && element.UnitPaymentOrder.IncomeTaxBy.ToUpper() == "SUPPLIER") { nominal -= element.UnitPaymentOrder.Amount.GetValueOrDefault() * (decimal)element.UnitPaymentOrder.IncomeTax.Rate.GetValueOrDefault(); } return(nominal); }); if (form.Type == "Tanpa Nomor VB") { model = new VBRealizationDocumentModel(form.Currency, form.Date, form.SuppliantUnit, documentNo, (decimal)amount); } else { var vbRequest = _dbContext.VBRequestDocuments.FirstOrDefault(entity => entity.Id == form.VBRequestDocument.Id.GetValueOrDefault()); if (vbRequest != null) { vbRequest.SetIsRealized(true, _identityService.Username, UserAgent); _dbContext.VBRequestDocuments.Update(vbRequest); } model = new VBRealizationDocumentModel(form.Date, vbRequest, documentNo, (decimal)amount); } EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent); _dbContext.VBRealizationDocuments.Add(model); _dbContext.SaveChanges(); AddItems(model.Id, form.Items, model.SuppliantDivisionName); AddUnitCosts(model.Id, form.Items.SelectMany(element => element.UnitPaymentOrder.UnitCosts).ToList()); _dbContext.SaveChanges(); return(model.Id); }
public async Task <ActionResult <AccountInformation> > PostAccountInformations([FromBody] AccountProfileFormViewModel accountProfile) { VerifyUser(); var model = new AccountInformation() { Fullname = accountProfile.Fullname, EmployeeID = accountProfile.EmployeeId, Username = accountProfile.Username, Dob = accountProfile.DOB, Gender = accountProfile.Gender, Religion = accountProfile.Religion, Email = accountProfile.Email, Password = accountProfile.Password, JobTitleName = accountProfile.JobTitlename, Department = accountProfile.Departmanet, Status = accountProfile.Status, JoinDate = accountProfile.JoinDate, CoorporateEmail = accountProfile.CoorporateEmail, SkillSet = accountProfile.SkillSet, }; EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent); _context.AccountInformations.Add(model); var assetmodel = new Asset() { AssetName = accountProfile.AssetName, AssetNumber = accountProfile.AssetNumber }; EntityExtension.FlagForCreate(assetmodel, _identityService.Username, UserAgent); _context.Assets.Add(assetmodel); var payrollmodel = new Payroll() { Salary = accountProfile.Salary, Tax = accountProfile.Tax, BPJSKesehatan = accountProfile.BPJSKesehatan, BPJSTenagaKerja = accountProfile.BPJSTenagakerja, NPWP = accountProfile.NPWP, NameBankAccount = accountProfile.NameBankAccount, Bank = accountProfile.Bank, BankAccountNumber = accountProfile.BankAccountNumber, BankBranch = accountProfile.BankBranch }; EntityExtension.FlagForCreate(payrollmodel, _identityService.Username, UserAgent); _context.Payrolls.Add(payrollmodel); await _context.SaveChangesAsync(); return(Created("", model)); }
public override void Create(FinishingPrintingSalesContractModel model) { SalesContractNumberGenerator(model); foreach (var detail in model.Details) { FinishingPrintingSalesContractDetailLogic.Create(detail); //EntityExtension.FlagForCreate(detail, IdentityService.Username, "sales-service"); } EntityExtension.FlagForCreate(model, IdentityService.Username, "sales-service"); DbSet.Add(model); }
public TechnicianModel CreateTechnician(string name) { TechnicianModel technician = new TechnicianModel { Name = name, IsDefault = true }; EntityExtension.FlagForCreate(technician, IdentityService.Username, UserAgent); dbContext.Technicians.Add(technician); return(technician); }
public override void CreateModel(PackingReceiptModel model) { model.ReferenceNo = $"RFNO-{model.Code}"; model.ReferenceType = $"Penerimaan Packing {model.StorageName}"; model.Type = "IN"; foreach (var item in model.Items) { EntityExtension.FlagForCreate(item, IdentityService.Username, UserAgent); } EntityExtension.FlagForCreate(model, IdentityService.Username, UserAgent); dbSet.Add(model); }
public override void UpdateModelAsync(int id, KanbanModel model) { if (model.Instruction != null && model.Instruction.Steps != null) { EntityExtension.FlagForUpdate(model.Instruction, IdentityService.Username, UserAgent); HashSet <int> stepIds = KanbanStepDbSet.Where(d => d.InstructionId == model.Instruction.Id).Select(d => d.Id).ToHashSet(); foreach (int stepId in stepIds) { var step = model.Instruction.Steps.FirstOrDefault(prop => prop.Id.Equals(stepId)); if (step == null) { step = KanbanStepDbSet.Where(w => w.Id == stepId).FirstOrDefault(); var stepIndicators = KanbanStepIndicatorDbSet.Where(w => w.StepId == step.Id).ToList(); EntityExtension.FlagForDelete(step, IdentityService.Username, UserAgent); KanbanStepDbSet.Update(step); foreach (var stepIndicator in stepIndicators) { EntityExtension.FlagForDelete(stepIndicator, IdentityService.Username, UserAgent); KanbanStepIndicatorDbSet.Update(stepIndicator); } } else { EntityExtension.FlagForUpdate(step, IdentityService.Username, UserAgent); KanbanStepDbSet.Update(step); foreach (var stepIndicator in step.StepIndicators) { EntityExtension.FlagForUpdate(stepIndicator, IdentityService.Username, UserAgent); KanbanStepIndicatorDbSet.Update(stepIndicator); } } } foreach (var step in model.Instruction.Steps) { if (step.Id == 0) { EntityExtension.FlagForCreate(step, IdentityService.Username, UserAgent); KanbanStepDbSet.Add(step); foreach (var stepIndicator in step.StepIndicators) { EntityExtension.FlagForCreate(stepIndicator, IdentityService.Username, UserAgent); KanbanStepIndicatorDbSet.Add(stepIndicator); } } } } base.UpdateModelAsync(id, model); }
public async Task <int> CreateMultiple(List <GarmentInternalPurchaseOrder> ListModel, string user, int clientTimeZoneOffset = 7) { int Created = 0; using (var transaction = dbContext.Database.BeginTransaction()) { try { foreach (var model in ListModel) { EntityExtension.FlagForCreate(model, user, USER_AGENT); do { model.PONo = CodeGenerator.Generate(); }while (ListModel.Count(m => m.PONo == model.PONo) > 1 || dbSet.Any(m => m.PONo.Equals(model.PONo))); model.IsPosted = false; model.IsClosed = false; foreach (var item in model.Items) { EntityExtension.FlagForCreate(item, user, USER_AGENT); item.Status = "PO Internal belum diorder"; item.RemainingBudget = item.BudgetPrice * item.Quantity; var garmentPurchaseRequestItem = dbContext.GarmentPurchaseRequestItems.Single(i => i.Id == item.GPRItemId); garmentPurchaseRequestItem.IsUsed = true; garmentPurchaseRequestItem.Status = "Sudah diterima Pembelian"; EntityExtension.FlagForUpdate(garmentPurchaseRequestItem, user, USER_AGENT); var garmentPurchaseRequest = dbContext.GarmentPurchaseRequests.Include(m => m.Items).Single(i => i.Id == model.PRId); garmentPurchaseRequest.IsUsed = garmentPurchaseRequest.Items.All(i => i.IsUsed == true); EntityExtension.FlagForUpdate(garmentPurchaseRequest, user, USER_AGENT); } dbSet.Add(model); } Created = await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }