public void SubmitOrder() { int p = 1; using (CocurrentDBEntities db = new CocurrentDBEntities()) { var log = db.InventoryLog; var inventory = db.Inventory; using (var transaction = db.Database.BeginTransaction()) { var inventory_model = inventory.FirstOrDefault(a => a.ProductId == p); inventory_model.ProductCount = inventory_model.ProductCount - 1; int stat = db.SaveChanges(); InventoryLog logmodel = new InventoryLog() { Title = "logged,see coccurence happening" }; log.Add(logmodel); db.SaveChanges(); Thread.Sleep(500); transaction.Commit(); } } //using() //using(Co) }
public int LockForEf() { int p = 1; int receive = 0; using (SaveChangeForConcurrency db = new SaveChangeForConcurrency()) { var log = db.InventoryLog; var inventory = db.Inventory; using (var transaction = db.Database.BeginTransaction()) { var inventory_model = inventory.FirstOrDefault(a => a.ProductId == p); inventory_model.ProductCount = inventory_model.ProductCount - 1; receive = db.SaveChanges(); InventoryLog logmodel = new InventoryLog() { Title = "logged,see coccurence happening" }; log.Add(logmodel); db.SaveChanges(); Thread.Sleep(500); transaction.Commit(); } } return(receive); //using() //using(Co) }
public InventoryTransaction(InventoryLog log) { ProductId = log.ProductId.GetValueOrDefault(); image = log.Product.Image; Name = log.Product.Name; CycleName = log.Transaction?.Cycle.Name; Quantity = log.Quantity.GetValueOrDefault(); OldQuantity = log.OldQnty.GetValueOrDefault(); NewQuantity = log.NewQnty.GetValueOrDefault(); typeId = log.ActionType.GetValueOrDefault(); date = log.CreatedDate?.ToString("dd/MM/yyyy HH:mm"); }
public TransactionModel(InventoryLog log) { this.InvId = log.Inventory.Id; this.TransId = log.Id; this.Quantity = log.Quantity; this.Size = log.Size; this.UnitId = log.Unit.Id; this.ActionId = log.InventoryAction.Id; this.Cost = log.Cost; this.Description = log.Inventory.Item.Description; this.TimeStamp = log.TransactionDate; }
/// <summary> /// Save the inventory change history log into invetoryLog /// </summary> /// <param name="db">current db</param> /// <param name="deliveryLogID">deliveryLOGID cause this change</param> /// <param name="inv1">From inventory</param> /// <param name="inv2">To inventory</param> /// <returns></returns> public int LogInventoryChange(DataContext db, int deliveryID, int deliveryLogID, Inventory inv1, Inventory inv2) { InventoryLog invLog = new InventoryLog(inv1, inv2); invLog.InventoryID = deliveryID; invLog.DeliveryLogID = deliveryLogID; invLog.ChangeType = (int)InventoryLogTypeEnum.Delivery; invLog.UpdateDate = CurrentUpdateDate; invLog.UpdateEmployeeID = CurrentEmployee.ID; db.InventoryLogsDB.Add(invLog); db.SaveChanges(); return(invLog.ID); }
static void Main(string[] args) { int seed = (int)DateTime.UtcNow.Ticks; Random = new DotNetRandom(seed); string consoleTitle = $"RogueSharp Test - Level 1 - Seed {seed}"; string fontFileName = "terminal8x8.png"; player = new Player(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ClassTypes.Archer, RLColor.White, new WeaponTest(), new TestArmour(), "dick"); MapGenerator mapGenerator = new MapGenerator(_mapWidth, _mapHeight, 20, 7, 13); DungeonMap = mapGenerator.CreateMap(); SaveTest save = new SaveTest(seed.ToString(), player.SavePlayer()); DungeonMap.UpdatePlayerFieldOfView(player); CommandSystem = new CommandSystem(); MessageLog = new MessageLog(); MessageLog.Add("Message 1"); InventoryLog = new InventoryLog(); InventoryLog.Add("Weapon: " + player.GetInventory().GetThing(0).GetName()); MessageLog.Add($"Level created with seed {seed}"); //tells rlnet to use the bitmap font and that each tile is 8x8px _rootConsole = new RLRootConsole(fontFileName, _screenWidth, _screenHeight, 8, 8, 1f, consoleTitle); //setting up other sections _mapConsole = new RLConsole(_mapWidth, _mapHeight); _messageConsole = new RLConsole(_messageWidth, _messageHeight); _statConsole = new RLConsole(_statWidth, _statHeight); _invConsole = new RLConsole(_invWidth, _invHeight); //event wiring _rootConsole.Update += OnRootConsoleUpdate; _rootConsole.Render += OnRootConsoleRender; //game loop call _rootConsole.Run(); }
/// <summary> /// Event handler for RLNET Render event /// </summary> private static void OnRootConsoleRender(object sender, UpdateEventArgs e) { //Blit other console sections to the root console //Blit: Bit BLock Transfer RLConsole.Blit(_mapConsole, 0, 0, _mapWidth, _mapHeight, _rootConsole, 0, _invHeight); RLConsole.Blit(_statConsole, 0, 0, _statWidth, _statHeight, _rootConsole, _mapWidth, 0); RLConsole.Blit(_messageConsole, 0, 0, _messageWidth, _messageHeight, _rootConsole, 0, _screenHeight - _messageHeight); RLConsole.Blit(_invConsole, 0, 0, _invWidth, _invHeight, _rootConsole, 0, 0); DungeonMap.Draw(_mapConsole); MessageLog.Draw(_messageConsole); InventoryLog.Draw(_invConsole); player.Draw(_mapConsole, DungeonMap); _rootConsole.Draw(); }
public void AddTransactionLog(Material material, Location location, double qty, TransactionType transactionType) { var log = new InventoryLog() { material = material, Location = location, TransactionType = transactionType, Created = DateTime.Now, CreatedBy = UserLogged, Modified = DateTime.Now, ModifiedBy = UserLogged }; _context.Add(log); _context.SaveChanges(); }
public JsonResult CheckAttend(string UDID, int port) { var obj = _inventoryService.GetInventorys().Where(p => p.Note.Equals(UDID)).FirstOrDefault(); if (obj != null) { var inven = new InventoryLog(); inven.DateCreated = DateTime.Now; //0 o trong, 1 o ngoai inven.IsImport = port == 0 ? true : false; inven.IsDelete = false; inven.InventoryId = obj.Id; inven.LocationId = 1; _inventoryLogService.CreateInventoryLog(inven); return(Json(1, JsonRequestBehavior.AllowGet)); } return(Json(0, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Updates the inventory entry for the item /// Calls to update shopping list /// Creates a transaction log entry /// </summary> /// <param name="action">ADD/REMOVE/CURRENT</param> /// <param name="quantity">Count Multiplier</param> /// <param name="size">Size of each Item</param> /// <param name="itemId">ID of the item we're updating</param> /// <param name="units">Units of quantity coming in</param> /// <returns></returns> private InventoryLog UpdateStock(TransactionModel model)//(StockUpdateEnum action, double quantity, double size, long itemId, Unit units, double cost) { #region Setup objects JourListDMContainer dm = new JourListDMContainer(); InventoryLog log = new InventoryLog(); var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) { return(null); } var inv = member.Inventories.FirstOrDefault(z => z.Id == model.InvId); if (inv == null) { return(null); } // Update the inventory numbers var action = dm.InventoryActions.Single(z => z.Id == model.ActionId).Description; var uaction = (StockUpdateEnum)Enum.Parse(typeof(StockUpdateEnum), action); #endregion #region Update inventory values var units = dm.Units.Single(z => z.Id == model.UnitId); double size; try { size = Tools.Tools.ConvertUnits(model.Size, units, inv.Unit); } catch (Exception e) { throw e; } double total = size * model.Quantity; switch (uaction) { case StockUpdateEnum.ADD: inv.OnHand += total; log.Cost = model.Cost; break; case StockUpdateEnum.REMOVE: model.Quantity *= -1; inv.OnHand -= total; model.Cost = 0; break; case StockUpdateEnum.ADJUST: if (inv.OnHand > total) { model.Quantity *= -1; model.Size = -1 * (inv.OnHand - total); } else // if inv.onhand < total { model.Size = total - inv.OnHand; } inv.OnHand = total; model.Cost = 0; break; default: break; } #endregion dm.SaveChanges(); #region Make a transaction log // Create an inventory transaction log.Quantity = model.Quantity; log.Inventory = inv; log.TransactionDate = DateTime.Now; log.InventoryAction = dm.InventoryActions.Single(z => z.Id == model.ActionId); log.Size = model.Size; log.Quantity = model.Quantity; log.Unit = dm.Units.Single(z => z.Id == model.UnitId); log.Cost = model.Cost; dm.SaveChanges(); model.TransId = log.Id; #endregion // With any inventory update, it's possible the item need to be included/excluded from the shopping list. UpdateShoppingList(inv); // Success return(log); }
public async Task <int> DeleteInventoryLog(InventoryLog InventoryLog) { return(await _IInventoryLogRepository.DeleteInventoryLog(InventoryLog)); }
public JsonResult CancelTransaction(int TransactionId) { //Auth Will checked if (TransactionId != 0) { try { var currentUserJobTitle = ((ClaimsIdentity)User.Identity)?.FindFirst("JobTitle").Value ?? string.Empty; var Transaction = UnitOfWork.TransactionBL.GetAllTransactionWithDetails(c => c.TransactionId == TransactionId).FirstOrDefault(); //var notification = UnitOfWork.NotificationsBL // .Find(n => n.TransactionId == TransactionId // && n.Notificationtype == (int)POPEnums.NotificationType.NotConfirmed // && n.ToUserId == Transaction.from // ).ToList(); // UnitOfWork.NotificationsBL if (Transaction != null) { // decrease inventory var FromUser = Transaction.FromUser; var FromUserIsBBx = Transaction.FromUser; var transactionDetails = Transaction.TransactionDetail; foreach (var item in transactionDetails) { if (FromUser != null && FromUser.JobTitle.Name.ToLower() == "bbx") { var CycleProd = UnitOfWork.CycleProductBL.FindOne(p => p.CycleId == Transaction.CycleId && p.ProductId == item.ProductId); var EdProduct = UnitOfWork.ProductBL.Find(p => p.ProductId == CycleProd.ProductId).FirstOrDefault(); if (EdProduct != null) { var NewLogTrans = new InventoryLog() { TransactionId = item.TransactionId, ProductId = EdProduct.ProductId, OldQnty = (int)EdProduct.InventoryQnty, UserId = FromUser.Id, CreatedDate = DateTime.Now, TransactionType = Transaction.TransType,//(int)POPEnums.TransactionTypes.Clearance, ActionType = (int)POPEnums.InventoryActionType.Increment, Quantity = item.TransAmount, NewQnty = (int)EdProduct.InventoryQnty + item.TransAmount, }; EdProduct.InventoryQnty += item.TransAmount; UnitOfWork.ProductBL.Update(EdProduct); UnitOfWork.InventoryLogBL.Add(NewLogTrans); } // will take effect when request approved // in case of confirmed from bbx if (Transaction.Status == (int)POPEnums.TransactionStatus.Pending) { if (CycleProd.Qunt > 0) { CycleProd.Qunt -= item.TransAmount; } if (CycleProd.RemainQunt > 0) { CycleProd.RemainQunt -= item.TransAmount; } UnitOfWork.CycleProductBL.Update(CycleProd); } } else if (FromUser != null && FromUser.JobTitle.Name.ToLower() == "hr") { UnitOfWork.UserClearanceBL.UpdateUserClearance(FromUser.Id, (int)Transaction.CycleId, item.ProductId, item.TransAmount, true); } else { return(Json(new { success = false, message = "No users found for this transaction" })); }; } Transaction.Status = (int)POPEnums.TransactionStatus.Canceled; Transaction.ModifiedDate = System.DateTime.Now; Transaction.ModfiedById = LoggedUserId; if (UnitOfWork.Complete(LoggedUserId) > 0) { return(Json(new { success = true, message = "Transaction canceled successfully" })); } else { return(Json(new { success = false, message = "Failed to cancel transaction" })); } } else { return(Json(new { success = false, message = "Transaction Not Found" })); } } catch { return(Json(new { success = false, message = ApplicationMessages.ErrorOccure })); } } else { return(Json(new { success = false, message = ApplicationMessages.ErrorOccure })); } }
public IActionResult NewTransaction(string cycleId, string userId, List <string> Arr) { try { List <string> ProductsItems = Arr; int CId = int.Parse(cycleId.ToString()); int UId = int.Parse(userId.ToString()); var BBxUser = UnitOfWork.CycleUserBL.GetUserCycle(c => c.CycleId == CId && c.User.JobTitle.Name.ToLower() == "bbx").FirstOrDefault(); if (BBxUser == null) { return(Json(new { success = false, message = "Transaction Failed : There is no BBx assinged in the cycle" })); } List <TransactionDetail> TranDetList = new List <TransactionDetail>(); List <InventoryLog> LogTransList = new List <InventoryLog>(); var notification = new List <Notifications>(); foreach (var item in ProductsItems) { var _arr = item.Split(':').Select(Int32.Parse).ToList(); int prodid = _arr[0]; if (_arr[1] < 1) { continue; } var EdProduct = UnitOfWork.ProductBL.Find(p => p.ProductId == prodid).FirstOrDefault(); //Log Transaction if (EdProduct != null) { var NewLogTrans = new InventoryLog() { ProductId = prodid, Quantity = _arr[1], UserId = BBxUser.Id, CreatedDate = DateTime.Now, TransactionType = (int)POPEnums.TransactionTypes.Delivery, ActionType = (int)POPEnums.InventoryActionType.Decrement, OldQnty = (int)EdProduct.InventoryQnty, NewQnty = (int)EdProduct.InventoryQnty - _arr[1], }; EdProduct.InventoryQnty -= _arr[1]; LogTransList.Add(NewLogTrans); } TransactionDetail NewTranDet = new TransactionDetail() { ProductId = prodid, TransAmount = _arr[1] }; TranDetList.Add(NewTranDet); } notification.Add(new Notifications { CreatedAt = DateTime.Now, Title = POPEnums.NotificationType.Unconfirmed.ToString(), Notificationtype = (int)POPEnums.NotificationType.Unconfirmed, IsSeen = false, ToUserId = BBxUser.Id }); Transaction NewTransObj = new Transaction() { CreateDate = System.DateTime.Now, CycleId = CId, CreatedById = LoggedUserId, Status = (int)POPEnums.TransactionStatus.New_Request, ToUserId = UId, TransactionDetail = TranDetList, TransType = (int)POPEnums.TransactionTypes.Delivery, FromUserId = BBxUser.Id, InventoryLog = LogTransList, Notifications = notification }; UnitOfWork.TransactionBL.Add(NewTransObj); try { if (UnitOfWork.Complete(LoggedUserId) > 0) { return(Json(new { success = true, message = ApplicationMessages.SaveSuccess })); } } catch { return(Json(new { success = false, message = ApplicationMessages.SaveFailed })); } } catch (Exception e) { return(Json(new { success = false, massege = ApplicationMessages.ErrorOccure })); } return(Json(new { success = false })); }
public void LogAsset(InventoryLog rec) { rec.Timestamp = DateTime.Now; context.InventoryLogs.Add(rec); Save(); }
public ActionResult SubmitStocks([Bind(Include = "Id,InventoryId,ItemId,Count")] InventoryLog log) { if (Request.Params.Get("InOut") == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } bool InOut = Request.Params.Get("InOut").ToString().Equals("True") ? true : false; Inventory inventory = db.Inventories.Find(log.InventoryId); var stocks = db.InventoryStocks.Where(x => (x.InventoryId == log.InventoryId) && (x.ItemId == log.ItemId)); // In case of relase : check whether stock amount is enough if (!InOut) { if (stocks.Count() <= 0 || stocks.First().Count < log.Count) { ModelState.AddModelError("Count", "Stock is not enough!"); ViewBag.Items = new SelectList(db.Items.ToList().Select( x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() } ), "Value", "Text"); ViewBag._InventoryId = inventory.Id.ToString(); ViewBag.InventoryName = inventory.Name; ViewBag.InOut = InOut; return(View("ManageStocks")); } } if (ModelState.IsValid) { log.InOrOut = InOut; log.DateTime = DateTime.Now; db.InventoryLogs.Add(log); if (stocks.Count() <= 0 && InOut) { InventoryStock newStock = new InventoryStock(); newStock.InventoryId = log.InventoryId; newStock.ItemId = log.ItemId; newStock.Count = log.Count; db.InventoryStocks.Add(newStock); } else { var stock = stocks.First(); if (InOut) { stock.Count = stock.Count + log.Count; } else { stock.Count = stock.Count - log.Count; } db.Entry(stock).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Items = new SelectList(db.Items.ToList().Select( x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() } ), "Value", "Text"); ViewBag._InventoryId = inventory.Id.ToString(); ViewBag.InventoryName = inventory.Name; ViewBag.InOut = InOut; return(View("ManageStocks")); }