public StockTake SaveStockTake(StockTake stockTake) { using (var context = new ApplicationDbContext()) { if (stockTake.Id != 0) { var entity = context.StockTakes.FirstOrDefault(x => x.Id == stockTake.Id); entity.Description = stockTake.Description; entity.Location = stockTake.Location; entity.Name = stockTake.Name; context.InventoryItems.RemoveRange(entity.Inventory); entity.Inventory = stockTake.Inventory; } else { stockTake.CreatedDate = DateTime.Now; context.StockTakes.Add(stockTake); } context.SaveChanges(); return(stockTake); } }
public override async Task GetAllStocks(HasChanged request, IServerStreamWriter <StockTake> responseStream, ServerCallContext context) { string query = "SELECT * FROM STOCKS;"; await db.Connection.OpenAsync(); var command = new MySqlCommand(query, db.Connection); var reader = await command.ExecuteReaderAsync(); while (await reader.ReadAsync()) { // Use item service to get the item Item item = await itemService.GetItem(new ItemGet() { ItemId = reader.GetFieldValue <uint>(1) }, context); // Enter info into StockTake message var Stocktake = new StockTake { Item = item, Info = new StockInfo { Stock = reader.GetFieldValue <int>(2) } }; // send stock take over stream await responseStream.WriteAsync(Stocktake); } }
public ActionResult Create([Bind(Include = "StockTakeId,StockTakeReference,StockTakeDescription")] StockTake stockTake) { if (ModelState.IsValid) { _stockTakeService.CreateStockTake(stockTake, CurrentUserId, CurrentTenantId, CurrentWarehouseId); return(RedirectToAction("Create")); } ViewBag.TenantId = new SelectList(_tenantServices.GetAllTenants(), "TenantId", "TenantName", stockTake.TenantId); ViewBag.WarehouseId = new SelectList(TenantLocationServices.GetAllTenantLocations(CurrentTenantId), "WarehouseId", "WarehouseName", stockTake.WarehouseId); return(View(stockTake)); }
public async Task <IActionResult> PostTransaction([FromBody] StockTakeAPI transactionApi) { APIResponse response = new APIResponse(); try { StockTake stockTake = new StockTake(); stockTake.EmployeeId = transactionApi.employeeId; stockTake.EmployeeName = transactionApi.employeeName; stockTake.Time = DateTime.Now; stockTake.StoreId = transactionApi.storeCode; _context.StockTake.Add(stockTake); //log record LogRecord log = new LogRecord(); log.TimeStamp = DateTime.Now; log.Tag = "Stock take"; log.Message = JsonConvert.SerializeObject(transactionApi); _context.LogRecord.Add(log); _context.SaveChanges(); for (int i = 0; i < transactionApi.stockTakeLines.Count; i++) { StockTakeLineAPI lineAPI = transactionApi.stockTakeLines[i]; StockTakeLine line = new StockTakeLine(); line.ArticleId = lineAPI.article.articleId; line.ArticleName = lineAPI.article.articleName; line.GoodQty = lineAPI.goodQty; line.RejectQty = lineAPI.rejectQty; line.WhGoodQty = lineAPI.whGoodQty; line.WhRejectQty = lineAPI.whRejectQty; line.StockTakeId = stockTake.Id; _context.Add(line); _context.SaveChanges(); } response.code = "1"; response.message = "Sucess Add Data"; } catch (Exception ex) { response.code = "0"; response.message = ex.ToString(); } return(Ok(response)); }
// GET: StockTakes/Details/5 public ActionResult Details(int?id) { if (!caSession.AuthoriseSession()) { return(Redirect((string)Session["ErrorUrl"])); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StockTake stockTake = _stockTakeService.GetStockTakeById(id ?? 0); if (stockTake == null) { return(HttpNotFound()); } return(View(stockTake)); }
public override async Task <Empty> AddStock(StockTake request, ServerCallContext context) { await db.Connection.OpenAsync(); var cmd = db.Connection.CreateCommand(); //await Stock.CloseAsync(); // await Stock.DisposeAsync(); cmd.CommandText = $"INSERT INTO STOCK (item_id,item_stock)" + $"VALUES({request.Item.ItemId},{request.Info.Stock});"; _ = await cmd.ExecuteReaderAsync(); await cmd.DisposeAsync(); return(new Empty()); }
public dynamic AddStocktake(string sess, [FromBody] StockTake AddObject) { { var admin = db.Users.Where(zz => zz.SessionID == sess).ToList(); if (admin == null) { dynamic toReturn = new ExpandoObject(); toReturn.Error = "Session is no longer available"; return(toReturn); } if (AddObject != null) { StockTake Takes = new StockTake(); Takes.AdminID = AddObject.AdminID; Takes.Description = AddObject.Description; Takes.Date = DateTime.Now; db.StockTakes.Add(Takes); db.SaveChanges(); int StockTakeID = db.StockTakes.Where(zz => zz.Description == AddObject.Description).Select(zz => zz.StockTakeID).FirstOrDefault(); foreach (StockTakeLine lines in AddObject.StockTakeLines) { StockTakeLine newObject = new StockTakeLine(); newObject.ItemID = lines.ItemID; newObject.StockTakeID = StockTakeID; newObject.Quantity = lines.Quantity; StockItem updateStock = db.StockItems.Where(zz => zz.ItemID == lines.ItemID).FirstOrDefault(); updateStock.QuantityInStock = lines.Quantity; db.StockTakeLines.Add(newObject); db.SaveChanges(); } return("success"); } else { return(null); } } }
public override async Task <StockInfo> ChangeStock(StockTake request, ServerCallContext context) { await db.Connection.OpenAsync(); var cmd = db.Connection.CreateCommand(); // Database lookup with id cmd.CommandText = $"UPDATE STOCK SET item_stock={request.Info.Stock} WHERE item_id={request.Item.ItemId};"; _ = await cmd.ExecuteReaderAsync(); await cmd.DisposeAsync(); //await Stock.CloseAsync(); // await Stock.DisposeAsync(); cmd.CommandText = $"SELECT * FROM STOCK WHERE item_id={request.Item.ItemId};"; var Stock = await cmd.ExecuteReaderAsync(); var Stockinfo = new StockInfo(); await Stock.ReadAsync(); Stockinfo.Stock = Stock.GetFieldValue <int>(2); await Stock.CloseAsync(); await Stock.DisposeAsync(); return(Stockinfo); }
public void AddToStockTake(StockTake stockTake) { base.AddObject("StockTake", stockTake); }
public static StockTake CreateStockTake(int stockTakeID, global::System.DateTime date, bool finalized) { StockTake stockTake = new StockTake(); stockTake.StockTakeID = stockTakeID; stockTake.Date = date; stockTake.Finalized = finalized; return stockTake; }