public async Task <int> CreateAsync(RO_Garment Model) { do { Model.Code = Code.Generate(); }while (this.DbSet.Any(d => d.Code.Equals(Model.Code))); CostCalculationGarment costCalculationGarment = await costCalGarmentLogic.ReadByIdAsync((int)Model.CostCalculationGarment.Id); //Model.CostCalculationGarment; foreach (var item in costCalculationGarment.CostCalculationGarment_Materials) { foreach (var itemModel in Model.CostCalculationGarment.CostCalculationGarment_Materials) { if (item.Id == itemModel.Id) { item.Information = itemModel.Information; } } } Model.CostCalculationGarment = null; Model.ImagesPath = await this.AzureImageFacade.UploadMultipleImage(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.ImagesFile, Model.ImagesPath); roGarmentLogic.Create(Model); int created = await DbContext.SaveChangesAsync(); await UpdateCostCalAsync(costCalculationGarment, (int)Model.Id); return(created); }
public async Task <int> CreateAsync(DeliveryNoteProductionModel model) { int result = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { int index = 0; do { model.Code = CodeGenerator.Generate(); model.MonthandYear = model.Month + " " + model.Year; }while (DbSet.Any(d => d.Code.Equals(model.Code))); //DOSalesNumberGenerator(model, index); deliveryNoteProductionLogic.Create(model); index++; result = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(result); }
public async Task <IActionResult> PutSales(int id, Sales sales) { if (id != sales.Id) { return(BadRequest()); } _context.Entry(sales).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SalesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <int> CreateAsync(SalesInvoiceModel model) { int result = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { int index = 0; do { model.Code = CodeGenerator.Generate(); }while (DbSet.Any(d => d.Code.Equals(model.Code))); SalesInvoiceNumberGenerator(model, index); salesInvoiceLogic.Create(model); index++; result = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(result); }
public async Task <IActionResult> PutOrderLine(int id, OrderLine orderLine) { if (id != orderLine.Id) { return(BadRequest()); } _context.Entry(orderLine).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderLineExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <int> CreateAsync(CostCalculationGarment model) { int Created = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { do { model.Code = CodeGenerator.Generate(); await CustomCodeGenerator(model); }while (this.DbSet.Any(d => d.Code.Equals(model.Code))); costCalculationGarmentLogic.Create(model); Created = await DbContext.SaveChangesAsync(); if (!string.IsNullOrWhiteSpace(model.ImageFile)) { model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile); } await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public async Task Consume(ConsumeContext <IProductUpdatedEvent> context) { using (SalesDbContext unitOfWork = new SalesDbContext()) { var updatedProductId = context.Message.Product.ProductId; var price = context.Message.Product.Price; if (unitOfWork.Products.Any(x => x.Id == updatedProductId)) { var productToUpdate = unitOfWork.Products.First(x => x.Id == updatedProductId); unitOfWork.Products.Attach(productToUpdate); productToUpdate.Price = price; await unitOfWork.SaveChangesAsync(); await Console.Out.WriteLineAsync($"Product {updatedProductId} price changed."); } else { unitOfWork.Products.Add(new Product { Id = updatedProductId, Price = price }); await unitOfWork.SaveChangesAsync(); await Console.Out.WriteLineAsync($"Product {updatedProductId} added."); } await context.Publish(CreateInventoryUpdatedEvent(updatedProductId, price)); } }
public async Task <IActionResult> PutCustomer(int id, Customer customer) { if (id != customer.Id) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> DeleteConfirmed(int id) { var employee = await db.Employees.SingleOrDefaultAsync(mbox => mbox.EmployeeId == id); db.Employees.Remove(employee); await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <int> CreateAsync(Rate model) { do { model.Code = CodeGenerator.Generate(); }while (this.DbSet.Any(d => d.Code.Equals(model.Code))); rateLogic.Create(model); return(await DbContext.SaveChangesAsync()); }
public async Task <int> CreateAsync(FinishingPrintingSalesContractModel model) { do { model.Code = CodeGenerator.Generate(); }while (this.DbSet.Any(d => d.Code.Equals(model.Code))); finishingPrintingSalesContractLogic.Create(model); return(await DbContext.SaveChangesAsync()); }
public async Task <int> CreateAsync(Efficiency model) { do { model.Code = CodeGenerator.Generate(); }while (this.DbSet.Any(d => d.Code.Equals(model.Code))); model.Value /= 100; efficiencyLogic.Create(model); return(await DbContext.SaveChangesAsync()); }
public Task <int> CreateAsync(DOSalesModel model) { do { model.Code = CodeGenerator.Generate(); }while (DbSet.Any(d => d.Code.Equals(model.Code))); DOSalesNumberGenerator(model); doAvalLogic.Create(model); return(DbContext.SaveChangesAsync()); }
public async Task <int> CreateAsync(SpinningSalesContractModel model) { do { model.Code = CodeGenerator.Generate(); }while (this.DbSet.Any(d => d.Code.Equals(model.Code))); var data = await CustomCodeGenerator(model); SpinningSalesContractLogic.Create(data); return(await DbContext.SaveChangesAsync()); }
private async Task HandleProductsAsync(ProductUpdated message) { var productsFromDb = await _dbContext.Products .Where(p => message.UpdatedItems.Select(i => i.ProductId).Contains(p.Id)) .Include(p => p.ProductCategory) .ToListAsync(); //await HandleProductCategoryAsync(message, productsFromDb); await HandleProductAsync(message, productsFromDb); await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Post(CategoryViewModel model, CancellationToken cancellationToken) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } var category = Mapper.Map <Category>(model); var result = await _context.Categories.AddAsync(category); await _context.SaveChangesAsync(); return(CreatedAtAction("Get", new { category.Id }, category)); }
public async Task <int> CreateAsync(GarmentSalesContract model) { //do //{ // model.Code = CodeGenerator.Generate(); //} //while (this.DbSet.Any(d => d.Code.Equals(model.Code))); CostCalculationGarment costCal = await DbContext.CostCalculationGarments.FirstOrDefaultAsync(a => a.Id.Equals(model.CostCalculationId)); //costCal.SCGarmentId= garmentSalesContractLogic.Create(model); await DbContext.SaveChangesAsync(); return(await UpdateCostCalAsync(costCal, (int)model.Id)); }
public async Task Handle(CancelOrder message, IMessageHandlerContext context) { // Find Order and update the database. var order = dbContext.OrderDetails.First(m => m.OrderId == message.OrderId); order.IsOrderCancelled = true; await dbContext.SaveChangesAsync().ConfigureAwait(false); }
public async Task <int> ValidateROGarment(CostCalculationGarment CostCalculationGarment, Dictionary <long, string> productDicts) { int Updated = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { var model = this.DbSet .Include(m => m.CostCalculationGarment_Materials) .FirstOrDefault(m => m.Id == CostCalculationGarment.Id); EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service"); model.IsValidated = true; foreach (var material in model.CostCalculationGarment_Materials) { var sentMaterial = CostCalculationGarment.CostCalculationGarment_Materials.FirstOrDefault(m => m.Id == material.Id); if (sentMaterial != null) { material.IsPosted = true; EntityExtension.FlagForUpdate(material, IdentityService.Username, "sales-service"); } } DbSet.Update(model); Updated = await DbContext.SaveChangesAsync(); model.CostCalculationGarment_Materials = model.CostCalculationGarment_Materials.Where(material => CostCalculationGarment.CostCalculationGarment_Materials.Any(oldMaterial => oldMaterial.Id == material.Id)).ToList(); if (CostCalculationGarment.CostCalculationGarment_Materials.All(m => !m.CategoryName.ToUpper().Equals("PROCESS"))) { await RO_Garment_ValidationLogic.CreateGarmentPurchaseRequest(model, productDicts); } else if (CostCalculationGarment.CostCalculationGarment_Materials.All(m => m.CategoryName.ToUpper().Equals("PROCESS"))) { await RO_Garment_ValidationLogic.AddItemsGarmentPurchaseRequest(model, productDicts); } else { throw new Exception("Kategori Ada Proses dan Lainnnya"); } transaction.Commit(); } //catch (ServiceValidationException e) //{ // transaction.Rollback(); // throw new ServiceValidationException(e.Message, null, null); //} catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Updated); }
public async Task <int> CreateAsync(CostCalculationGarment model) { do { model.Code = CodeGenerator.Generate(); await CustomCodeGenerator(model); }while (this.DbSet.Any(d => d.Code.Equals(model.Code))); model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile); costCalculationGarmentLogic.Create(model); if (model.ImagePath != null) { model.ImagePath = await this.AzureImageFacade.UploadImage(model.GetType().Name, model.Id, model.CreatedUtc, model.ImageFile); } model.IsValidated = false; costCalculationGarmentLogic.Create(model); return(await DbContext.SaveChangesAsync()); }
public async Task <int> CreateAsync(SalesInvoiceModel model) { int result = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { int index = 0; do { model.Code = CodeGenerator.Generate(); }while (DbSet.Any(d => d.Code.Equals(model.Code))); SalesInvoiceNumberGenerator(model, index); DeliveryOrderNumberGenerator(model); salesInvoiceLogic.Create(model); index++; result = await DbContext.SaveChangesAsync(); if (model.SalesInvoiceCategory == "DYEINGPRINTING") { foreach (var detail in model.SalesInvoiceDetails) { var ItemIds = detail.SalesInvoiceItems.Select(s => s.ProductId).ToList(); UpdateTrueToShippingOut(detail.ShippingOutId, ItemIds); } } transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(result); }
public async Task <IActionResult> Put(ProductViewModel model, CancellationToken cancellationToken = default(CancellationToken)) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } var product = await _context.Products.FirstOrDefaultAsync(p => p.Id == model.Id, cancellationToken); if (product == null) { return(NotFound()); } product = Mapper.Map <ProductViewModel, Product>(model); await _context.SaveChangesAsync(cancellationToken); return(Ok()); }
public async Task SaveEventAndProductContextChangesAsync(IntegrationEvent @event, CancellationToken cancellationToken = default(CancellationToken)) { //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency await ResilientTransaction.New(_salesContext) .ExecuteAsync(async() => { // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction await _salesContext.SaveChangesAsync(cancellationToken); await _eventLogService.SaveEventAsync(@event, _salesContext.Database.CurrentTransaction.GetDbTransaction()); }); }
public async Task <Data.Domains.Sales> SaveSalesAsync(SalesCommandReceived dto) { var products = await _stockService.GetAvailableStockProductAsync(dto.SoldItems); decimal totalAmountToPay = 0; Data.Domains.Sales salesToSave = new(); List <SalesDetails> salesItemsToSave = new(); if (!await _dbContext.Customers.AnyAsync(c => c.Id == dto.CustomerId)) { salesToSave.Customer = new Customer { Id = dto.CustomerId, Email = dto.Email, Mobile = dto.Mobile, Name = dto.CustomerName, }; await _dbContext.Customers.AddAsync(salesToSave.Customer); } dto.SoldItems.ForEach(c => { var productToUpdate = products.FirstOrDefault(p => p.Id == c.ProductId); var price = productToUpdate.Price * c.Qty; totalAmountToPay += price; salesItemsToSave.Add(new SalesDetails { Price = price, ProductId = c.ProductId, Qty = c.Qty }); c.ProductName = productToUpdate.Name; productToUpdate.HoldQty -= c.Qty; productToUpdate.StockQty -= c.Qty; _dbContext.Products.Update(productToUpdate); }); salesToSave.CustomerId = dto.CustomerId; salesToSave.TotalPrice = totalAmountToPay; salesToSave.CustomerId = dto.CustomerId; salesToSave.SoldAt = DateTimeOffset.UtcNow; salesToSave.Reference = dto.Reference; salesToSave.SalesDetails = salesItemsToSave; await _dbContext.Sales.AddAsync(salesToSave); await _dbContext.SaveChangesAsync(); return(salesToSave); }
public async Task <int> CreateAsync(SalesReceiptModel model) { int result = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { int index = 0; foreach (var item in model.SalesReceiptDetails) { var updateToSalesInvoice = DbContext.SalesInvoices.FirstOrDefault(x => x.Id == item.SalesInvoiceId); updateToSalesInvoice.TotalPaid = item.Paid; updateToSalesInvoice.IsPaidOff = item.IsPaidOff; } do { model.Code = CodeGenerator.Generate(); }while (DbSet.Any(d => d.Code.Equals(model.Code))); SalesReceiptNumberGenerator(model, index); salesReceiptLogic.Create(model); index++; result = await DbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(result); }
public async Task <int> CreateAsync(RO_Garment Model) { do { Model.Code = Code.Generate(); }while (this.DbSet.Any(d => d.Code.Equals(Model.Code))); CostCalculationGarment costCalculationGarment = await costCalGarmentLogic.ReadByIdAsync((int)Model.CostCalculationGarment.Id); //Model.CostCalculationGarment; Model.CostCalculationGarment = null; Model.ImagesPath = await this.AzureImageFacade.UploadMultipleImage(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.ImagesFile, Model.ImagesPath); roGarmentLogic.Create(Model); await DbContext.SaveChangesAsync(); //Model.ImagesPath = await this.AzureImageService.UploadMultipleImage(Model.GetType().Name, Model.Id, Model._CreatedUtc, Model.ImagesFile, Model.ImagesPath); //await this.UpdateAsync((int)Model.Id, Model); //update CostCal return(await UpdateCostCalAsync(costCalculationGarment, (int)Model.Id)); }
public async Task Handle(AcceptOrder message, IMessageHandlerContext context) { // Find Order and update the database. var order = dbContext.OrderDetails.First(m => m.OrderId == message.OrderId); order.IsOrderAccepted = true; await dbContext.SaveChangesAsync().ConfigureAwait(false); // Publish event await context.Publish(new OrderAccepted { OrderId = message.OrderId, ProductId = message.ProductId }).ConfigureAwait(false); }
public async Task <IActionResult> PutAsync(Guid id, int productid, int quantity) { _logger.LogInformation($"Incoming PUT item in shoppingbasket {id} productId:{productid} quantity:{quantity}"); //Validate is productid is valid var shoppingBasketProduct = await _salesDbContext.ShoppingBasketProducts.Where(x => x.ProductId == productid).FirstOrDefaultAsync(); if (shoppingBasketProduct == null) { return(NotFound(new ErrorModelPoco() { ErrorMessage = $"Product with id {productid} not found" })); } var item = _salesDbContext.ShoppingBasketItems.Where(x => x.ProductID == productid && x.ShoppingBasketID == id).SingleOrDefault(); //If new item and quantity is more then 0 if (item == null && quantity > 0) { _salesDbContext.ShoppingBasketItems.Add(new ShoppingBasketItem() { ShoppingBasketID = id, ProductID = productid, Quantity = quantity, DateCreated = DateTime.Now, ModifiedDate = DateTime.Now }); } //If existing item and quantity is more then 0 else if (item != null && quantity > 0) { item.Quantity = quantity; item.ModifiedDate = DateTime.UtcNow; _salesDbContext.ShoppingBasketItems.Update(item); } //If existing item and quantity is 0 else if (item != null && quantity == 0) { _salesDbContext.ShoppingBasketItems.Remove(item); } var result = await _salesDbContext.SaveChangesAsync(); var actionResult = await GetShoppingCartAsync(id) as OkObjectResult; return(Ok(actionResult.Value)); }
public async Task Handle(StoreOrder message, IMessageHandlerContext context) { await dbContext.OrderDetails.AddAsync(new OrderDetail { ProductId = message.ProductId, OrderPlacedOn = message.OrderPlacedOn, IsOrderAccepted = false, OrderId = message.OrderId, Price = GetPriceFor(message.ProductId) }).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); // Publish event await context.Publish(new OrderPlaced { OrderId = message.OrderId, ProductId = message.ProductId }).ConfigureAwait(false); }
public async Task <int> CreateAsync(FinishingPrintingCostCalculationModel model) { int created = 0; finishingPrintingCostCalculationLogic.Create(model); created += await DbContext.SaveChangesAsync(); var chemicalModels = model.Machines.ToList().SelectMany(entity => { var result = entity.Chemicals.ToList().Select(chemical => { chemical.CostCalculationId = model.Id; return(chemical); }); return(result); }); ChemicalDBSet.UpdateRange(chemicalModels); created += await DbContext.SaveChangesAsync(); return(created); }