public async Task <int> CreateAsync(StockTransferNote model) { int Created = 0; using (var transaction = this.DbContext.Database.BeginTransaction()) { try { model.Code = CodeGenerator.GenerateCode(); model.FlagForCreate(IdentityInterface.Username, UserAgent); model.FlagForUpdate(IdentityInterface.Username, UserAgent); foreach (var item in model.StockTransferNoteItems) { item.FlagForCreate(IdentityInterface.Username, UserAgent); item.FlagForUpdate(IdentityInterface.Username, UserAgent); } DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); await CreateInventoryDocument(model, "OUT", "CREATE"); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } } return(Created); }
public async Task <IActionResult> PutStock(string id, Stock stock) { if (id != stock.Description) { return(BadRequest()); } _context.Entry(stock).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StockExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <Dealer> Add(Dealer car) { _inventoryDbContext.Dealers.Add(car); await _inventoryDbContext.SaveChangesAsync(); return(car); }
//public Task GetDTO(int id) //{ // throw new System.NotImplementedException(); //} public async Task <Car> Add(Car car) { _inventoryDbContext.Cars.Add(car); await _inventoryDbContext.SaveChangesAsync(); return(car); }
public async Task <IActionResult> PutProductInventory(int id, ProductInventory productInventory) { if (id != productInventory.Id) { return(BadRequest()); } _context.Entry(productInventory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductInventoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <int> CreateAsync(FPReturnInvToPurchasing model) { int Created = 0; using (var transaction = DbContext.Database.BeginTransaction()) { try { IFpRegradingResultDocsService fpRegradingResultDocsService = ServiceProvider.GetService <IFpRegradingResultDocsService>(); foreach (FPReturnInvToPurchasingDetail detail in model.FPReturnInvToPurchasingDetails) { fpRegradingResultDocsService.UpdateIsReturnedToPurchasing(detail.FPRegradingResultDocsId, true); detail.FlagForCreate(IdentityService.Username, UserAgent); detail.FlagForUpdate(IdentityService.Username, UserAgent); } model = await this.NoGenerator(model); DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); await CreateInventoryDocumentAsync(model, "OUT"); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception("Insert Error : " + e.Message); } } return(Created); }
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 <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 <int> CreateAsync(Models.FpRegradingResultDocs model) { int Created = 0; using (var transaction = this.DbContext.Database.BeginTransaction()) { try { model = await this.CustomCodeGenerator(model); model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); foreach (var item in model.Details) { item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); } DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); await CreateInventoryDocumentAsync(model, "IN"); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(Created); }
public async Task <T> AddAsync(T entity) { await _dbContext.Set <T>().AddAsync(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public async Task Create(InventoryWeavingDocument model) { //var bonCheck = this.DbSetDoc.FirstOrDefault(s => s.Date.Date == model.Date.Date && s.BonType == model.BonType && s.Type == "OUT"); // var bonCheck = this.DbContext.InventoryWeavingDocuments.Where(s => s.Date.Date == model.Date.Date && s.BonType == model.BonType && s.Type == "OUT").FirstOrDefault(); // if (bonCheck == null) //{ model.BonNo = GenerateBon(model.BonType, model.Date); model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); foreach (var item in model.Items) { item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); } DbSetDoc.Add(model); var result = await DbContext.SaveChangesAsync(); foreach (var item in model.Items) { InventoryWeavingMovement movement = new InventoryWeavingMovement { ProductOrderName = item.ProductOrderName, BonNo = model.BonNo, ReferenceNo = item.ReferenceNo, Construction = item.Construction, Grade = item.Grade, //Piece = item.Piece, MaterialName = item.MaterialName, WovenType = item.WovenType, Width = item.Width, Yarn1 = item.Yarn1, Yarn2 = item.Yarn2, YarnType1 = item.YarnType1, YarnType2 = item.YarnType2, YarnOrigin1 = item.YarnOrigin1, YarnOrigin2 = item.YarnOrigin2, UomId = item.UomId, UomUnit = item.UomUnit, Quantity = item.Quantity, QuantityPiece = item.QuantityPiece, ProductRemark = item.ProductRemark, Type = model.Type, InventoryWeavingDocumentId = model.Id, InventoryWeavingDocumentItemId = item.Id }; movement.FlagForCreate(IdentityService.Username, UserAgent); movement.FlagForUpdate(IdentityService.Username, UserAgent); DbSetMovement.Add(movement); } var result2 = await DbContext.SaveChangesAsync(); }
public async Task <int> CreateAsync(GarmentLeftoverWarehouseReceiptFabric model) { using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction()) { try { int Created = 0; model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); model.ReceiptNoteNo = GenerateNo(model); foreach (var item in model.Items) { item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); } DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); foreach (var item in model.Items) { GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock { ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.FABRIC, UnitId = model.UnitFromId, UnitCode = model.UnitFromCode, UnitName = model.UnitFromName, PONo = item.POSerialNumber, UomId = item.UomId, UomUnit = item.UomUnit, Quantity = item.Quantity, ProductCode = item.ProductCode, ProductId = item.ProductId, ProductName = item.ProductName, BasicPrice = item.BasicPrice }; await StockService.StockIn(stock, model.ReceiptNoteNo, model.Id, item.Id); } await UpdateUnitExpenditureNoteIsReceived(model.UENId, true); transaction.Commit(); return(Created); } catch (Exception e) { transaction.Rollback(); throw e; } } }
public async Task <IActionResult> Create([Bind("ProductId,Description,QtyOnHand,ReorderPoint,Status,Cost,Price")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("VendorId,Name,Status,Phone,Email")] Vendor vendor) { if (ModelState.IsValid) { _context.Add(vendor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vendor)); }
public async Task <IActionResult> Create([Bind("Id,Name")] RoastModel roastModel) { if (ModelState.IsValid) { _context.Add(roastModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(roastModel)); }
public async Task <int> CreateAsync(GarmentLeftoverWarehouseReceiptFinishedGood model) { int Created = 0; using (var transaction = DbContext.Database.CurrentTransaction ?? DbContext.Database.BeginTransaction()) { try { model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); model.FinishedGoodReceiptNo = GenerateNo(model); foreach (var item in model.Items) { item.FlagForCreate(IdentityService.Username, UserAgent); item.FlagForUpdate(IdentityService.Username, UserAgent); } DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); foreach (var item in model.Items) { GarmentLeftoverWarehouseStock stock = new GarmentLeftoverWarehouseStock { ReferenceType = GarmentLeftoverWarehouseStockReferenceTypeEnum.FINISHED_GOOD, UnitId = model.UnitFromId, UnitCode = model.UnitFromCode, UnitName = model.UnitFromName, RONo = item.RONo, LeftoverComodityCode = item.LeftoverComodityCode, LeftoverComodityId = item.LeftoverComodityId, LeftoverComodityName = item.LeftoverComodityName, Quantity = item.Quantity, BasicPrice = item.BasicPrice }; await StockService.StockIn(stock, model.FinishedGoodReceiptNo, model.Id, item.Id); await UpdateExpenditureGoodIsReceived(item.ExpenditureGoodId, "true"); } transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } } return(Created); }
public async Task <ActionResult> Create([Bind(Include = "id,productName,partNumber,productLabel,startingInventory,InventoryReceived,InventoryShipped,InventoryOnHand,MinimumRequired")] Products products) { if (ModelState.IsValid) { db.Products.Add(products); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(products)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Username,Password,ConfirmPassword,Role,BranchId")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BranchId"] = new SelectList(_context.Branches, "BranchId", "BranchId", user.BranchId); return(View(user)); }
public async Task <int> AddUser(User user) { if (_context != null) { await _context.UserInformations.AddAsync(user); await _context.SaveChangesAsync(); return(user.UserId); } return(0); }
//Add Product public async Task <int> AddProduct(Product product) { if (_context != null) { await _context.ProductDetailss.AddAsync(product); await _context.SaveChangesAsync(); return(product.productId); } return(0); }
public async Task <int> Create(InventoryMovement model) { int Created = 0; var internalTransaction = DbContext.Database.CurrentTransaction == null; var transaction = !internalTransaction ? DbContext.Database.CurrentTransaction : DbContext.Database.BeginTransaction(); try { model.No = GenerateNo(model); model.FlagForCreate(IdentityService.Username, UserAgent); model.FlagForUpdate(IdentityService.Username, UserAgent); IInventorySummaryService summary = ServiceProvider.GetService <IInventorySummaryService>(); this.DbSet.Add(model); Created = await DbContext.SaveChangesAsync(); //var SumQty = this.dbSet.Where(a => a._IsDeleted == false && a.StorageId == model.StorageId && a.ProductId == model.ProductId && a.UomId == model.UomId).Sum(a => a.Quantity); var SumQty = this.DbSet.OrderByDescending(a => a._CreatedUtc).FirstOrDefault(a => a._IsDeleted == false && a.StorageId == model.StorageId && a.ProductId == model.ProductId && a.UomId == model.UomId); var SumStock = this.DbSet.Where(a => a._IsDeleted == false && a.StorageId == model.StorageId && a.ProductId == model.ProductId && a.UomId == model.UomId).Sum(a => a.StockPlanning); InventorySummary summaryModel = new InventorySummary { ProductId = model.ProductId, ProductCode = model.ProductCode, ProductName = model.ProductName, UomId = model.UomId, UomUnit = model.UomUnit, StockPlanning = SumStock, Quantity = SumQty.After, StorageId = model.StorageId, StorageCode = model.StorageCode, StorageName = model.StorageName }; await summary.Create(summaryModel); if (internalTransaction) { transaction.Commit(); } return(Created); } catch (Exception e) { if (internalTransaction) { transaction.Rollback(); } throw new Exception(e.Message); } }
public async Task <IActionResult> Create([Bind("ID, ProductID, StaffID, RequestedQuantity, ApprovalStatus")] StockRequest stockRequest) { if (ModelState.IsValid) { stockRequest.ProductID = 1; stockRequest.StaffID = 1; _context.Add(stockRequest); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stockRequest)); }
public async Task <ActionResult> Create(VendorModel newVendor) { try { _context.Add(newVendor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Edited(Manufacturer manufacturer) { if (manufacturer.Id == 0) { _context.Add(manufacturer); await _context.SaveChangesAsync(); } else { _context.Update(manufacturer); await _context.SaveChangesAsync(); } return(RedirectToAction("Index")); }
public async Task <bool> DeleteProductAsync(int id) { var product = await context.Product.FirstOrDefaultAsync(p => p.Id == id); context.Remove(product); try { return(await context.SaveChangesAsync() > 0 ? true : false); } catch (Exception exp) { logger.LogError($"Error in {nameof(DeleteProductAsync)}: " + exp.Message); } return(false); }
public async Task <bool> Handle( UpdateStoreProductPriceCommand request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var storeProductPrice = await _dbContext.StoreProductPrices .FirstOrDefaultAsync(x => x.StoreId == request.StoreId && x.ProductId == request.ProductId); if (storeProductPrice == null) { throw new Exception($"Couldn't find any store-product-price # {request.StoreId} & {request.ProductId}"); } storeProductPrice.UpdateStoreProductPrice( request.Price, request.Rop, request.Eoq); _dbContext.StoreProductPrices.Update(storeProductPrice); var effectedRows = await _dbContext.SaveChangesAsync(); return(effectedRows > 0); }
public async Task <IHttpActionResult> PutInventory(int id, Models.Inventory request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var inventory = db.Inventories.Find(id); inventory.Quantity -= request.Quantity; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InventoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <bool> Handle( AddStoreProductPriceCommand request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var store = await _dbContext.Stores .FirstOrDefaultAsync(x => x.Id == request.StoreId); if (store == null) { throw new Exception($"Couldn't find any store # {request.StoreId}"); } var storeProductPrice = StoreProductPrice.Of( Guid.NewGuid(), store.Id, request.ProductId, request.Price, request.Rop, request.Eoq); await _dbContext.StoreProductPrices.AddAsync(storeProductPrice); var effectedRows = await _dbContext.SaveChangesAsync(); return(effectedRows > 0); }
public async Task <IActionResult> Register(UserAccount userAccount) { if (userAccount != null && !string.IsNullOrEmpty(userAccount.Email) && !string.IsNullOrEmpty(userAccount.Password)) { var passwordDetails = PasswordProtector.GetHashAndSalt(userAccount.Password); userAccount.Password = passwordDetails.HashText; userAccount.PasswordSalt = passwordDetails.SaltText; userAccount.HashIteration = passwordDetails.HashIteration; userAccount.HashLength = passwordDetails.HashLength; userAccount.CreatedDate = DateTime.Now; userAccount.UpdateDate = DateTime.Now; userAccount.Version = 1; userAccount.UserName = userAccount.Email; this.inventoryDbContext.UserAccounts.Add(userAccount); await inventoryDbContext.SaveChangesAsync(); } else { return(BadRequest("Required data for user registeration not found")); } return(Ok()); }
public async Task <int> CreateProduct(Product product) { // Add Product product.CreatedOn = DateTime.Now; _context.Add(product); // Add 0 stock var stock = new Stock { Quantity = 0, Product = product }; _context.Add(stock); await _context.SaveChangesAsync(); return(product.Id); }