public async Task<ActionResult> Edit(InventoryJournal inventoryJournal, int? quantity, string typeOfOperations)
        {
            var dbInventoryJournalRecord = _db.InventoryJournals.Find(inventoryJournal.RecordId);
           
            if (quantity!=null && typeOfOperations == "Credit" )
            {
                
                dbInventoryJournalRecord.Credit = quantity;
                dbInventoryJournalRecord.Debit = 0;

                //inventoryJournal.Returned = 0;
                //inventoryJournal.Allocated = 0;

            }

            if (quantity != null && typeOfOperations == "Debit")
            {
                dbInventoryJournalRecord.Debit = quantity;
                dbInventoryJournalRecord.Credit = 0;
                 
                
                //inventoryJournal.Returned = 0;
                //inventoryJournal.Allocated = 0;

            }

            dbInventoryJournalRecord.DateOfEntry = inventoryJournal.DateOfEntry;
            dbInventoryJournalRecord.Memo = inventoryJournal.Memo;
            dbInventoryJournalRecord.DoorId = inventoryJournal.DoorId;


             
                
                await _db.SaveChangesAsync();
                return RedirectToAction("Index");
            
            
            return View(inventoryJournal);
        }
        public ActionResult Create(int doorId, DateTime? dateOfEntry, int quantity, string memo, string typeOfOperations)
        {
            string rqs = Request.Params["button"];

            if (dateOfEntry ==null)
            {
                dateOfEntry = DateTime.Now;
            }


            if (rqs == "Сохранить")
            {
                var myRecord = new InventoryJournal
                {
                    FactoryId = FactoryName.FactoryId,
                    DoorId = doorId,
                    DateOfEntry = dateOfEntry,
                    Memo = memo
                };

                if (typeOfOperations == "Credit")
                {
                    myRecord.Credit = quantity;
                    _db.usp_RecordCredit(FactoryName.FactoryId, doorId, quantity);

                    myRecord.Debit = 0;
                     
                }

                else if (typeOfOperations == "Debit")
                {
                    myRecord.Debit = quantity;
                    _db.usp_RecordDebit(FactoryName.FactoryId, doorId, quantity);

                    myRecord.Credit = 0;
                }



                myRecord.Returned = 0;
                myRecord.Allocated = 0;
                var balanceForDor =
                    _db.InventoryBalances.SingleOrDefault(b => b.DoorId == doorId && b.FactoryId == FactoryName.FactoryId);
                myRecord.Balance = balanceForDor.Balance;

                if (ModelState.IsValid)
                {
                    _db.InventoryJournals.Add(myRecord);
                    _db.SaveChanges();
                    return RedirectToAction("Index");
                }
                 
                

              }
 
          
                //TODO: Make checkconstraint for DateOfEntry (must be mandatory)

            return RedirectToAction("Create", new { typeOfOperations, doorId, factoryId = FactoryName.FactoryId });
        }