コード例 #1
0
        public JsonResult AddRequestItem(Request request, int LocationID)
        {
            try
            {
                using (var context = new InventoryDbContext())//Use DbInventory
                {
                    ERequest eRequest = new ERequest()
                    {
                        UserId       = UserId,
                        RequiredDate = request.RequiredDate,
                        //RequisitionType = request.RequisitionType,
                        SpecialInstruction = request.SpecialInstruction,
                        LocationId         = LocationID,
                        Status             = "Pending"
                    };
                    context.Request.Add(eRequest); //Add Data
                    context.SaveChanges();         //Execute insert or changes

                    int currentRequestID = 0;      //initialize currentID
                    //Select current requestID
                    int reqID = (from req in context.Request
                                 orderby req.RequestId descending
                                 select req.RequestId).FirstOrDefault();
                    currentRequestID = reqID;//Put value to inventoryItemID
                    foreach (var items in request.RequestItems)
                    {
                        ERequestItem eRequestItem = new ERequestItem()
                        {
                            RequestId       = currentRequestID,
                            InventoryItemId = items.InventoryItemID,
                            Quantity        = items.Quantity,
                            Description     = items.Description
                        };
                        context.RequestItem.Add(eRequestItem);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.ToString()));
            }
            return(Json(string.Empty));
        }
コード例 #2
0
        public int UpdateIsReturnedToPurchasing(int fPRegradingResultDocsId, bool flag)
        {
            var model = DbContext.fpRegradingResultDocs.FirstOrDefault(x => x.Id == fPRegradingResultDocsId);

            //Models.FpRegradingResultDocs model = new Models.FpRegradingResultDocs { Id = fPRegradingResultDocsId, IsReturnedToPurchasing = flag };
            model.IsReturnedToPurchasing = flag;
            //DbContext.fpRegradingResultDocs.Attach(model);
            //DbContext.Entry(model).Property(x => x.IsReturnedToPurchasing).IsModified = true;
            return(DbContext.SaveChanges());
        }
コード例 #3
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                try
                {
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Database Error : " + ex.Message;
                    return(View(category));
                }
            }

            return(View(category));
        }
コード例 #4
0
        public IActionResult Delete(int Id)
        {
            var removeManufacturer = _context.Manufacturers.SingleOrDefault(m => m.Id == Id);

            if (removeManufacturer != null)
            {
                _context.Manufacturers.Remove(removeManufacturer);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
コード例 #5
0
 public ActionResult CreatePurchase(string sessionId)
 {
     if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
     {
         using (var db = new InventoryDbContext())
         {
             List <ProductCatalogue> pc = new List <ProductCatalogue>();
             //                List<Inventory> inv = new List<Inventory>();
             List <ProductSupplier> ps = new List <ProductSupplier>();
             //                inv = db.inventories.ToList();
             pc = db.productCatalogues.ToList();
             ps = db.productSuppliers.ToList();
             foreach (var pcs in pc)
             {
                 //                    foreach (var invs in inv)
                 //                    {
                 //                        if (pcs.itemNumber == invs.itemNumber)
                 //                        {
                 //                            pcs.quantity = invs.quantity;
                 //                        }
                 //                    }
                 foreach (var pss in ps)
                 {
                     if (pss.itemNumber == pcs.itemNumber)
                     {
                         if (pss.preference == 1)
                         {
                             pcs.supplier1 = pss.id;
                         }
                         else if (pss.preference == 2)
                         {
                             pcs.supplier2 = pss.id;
                         }
                         else if (pss.preference == 3)
                         {
                             pcs.supplier3 = pss.id;
                         }
                     }
                 }
             }
             db.SaveChanges();
             ViewData["pc"] = pc;
             //ViewData["inv"] = inv;
             ViewData["ps"]        = ps;
             ViewData["staffname"] = userServices.getUserBySessionId(sessionId).employee.empName;
             ViewData["sessionId"] = sessionId;
             return(View());
         }
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
 }
コード例 #6
0
        public DTOs.Order CreateOrder(DTOs.Order order)
        {
            order.DateCreated ??= DateTime.Now;
            order.DateLastModified ??= DateTime.Now;

            var mappedEntityOrder = Mapper.Map <Entities.Order>(order);
            var orderAdded        = InventoryDbContext.Orders.Add(mappedEntityOrder).Entity;

            InventoryDbContext.SaveChanges();

            return(Mapper.Map <DTOs.Order>(orderAdded));
        }
コード例 #7
0
        public IHttpActionResult PostInventory(Inventory inventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Inventories.Add(inventory);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = inventory.ID }, inventory));
        }
コード例 #8
0
        public GoodsReceiptModel AddGoodsReceipt(GoodsReceiptModel model)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    model.GoodsReceiptItem.ForEach(item =>
                    {
                        item.CreatedOn = DateTime.Now;  //Assign Today's date as CreatedOn
                        item.CreatedBy = model.CreatedBy;
                    });
                    model.CreatedOn = DateTime.Now;

                    db.GoodsReceipts.Add(model);


                    //Save Goods Receipt to DB

                    db.SaveChanges();

                    StockModel stockItem = new StockModel();
                    //If GR generated then save items in  Stock table
                    int SavedGoodsReceiptId = model.GoodsReceiptID;
                    if (SavedGoodsReceiptId > 0)
                    {
                        model.GoodsReceiptItem.ForEach(item =>
                        {
                            stockItem = new StockModel();
                            stockItem.GoodsReceiptItemId = item.GoodsReceiptItemId;
                            stockItem.ItemId             = item.ItemId;
                            stockItem.BatchNO            = item.BatchNO;
                            stockItem.ExpiryDate         = item.ExpiryDate;
                            stockItem.ReceivedQuantity   = item.ReceivedQuantity + item.FreeQuantity;
                            stockItem.AvailableQuantity  = item.ReceivedQuantity + item.FreeQuantity;
                            stockItem.ReceiptDate        = model.GoodsReceiptDate;
                            stockItem.CreatedBy          = item.CreatedBy;
                            stockItem.CreatedOn          = item.CreatedOn;
                            db.Stock.Add(stockItem);
                        });
                        //Save => Stock Items in stock table
                        db.SaveChanges();

                        PurchaseOrderModel poitems = db.PurchaseOrders.Where(a => a.PurchaseOrderId == model.PurchaseOrderId).FirstOrDefault();
                        if (poitems != null)
                        {
                            poitems.POStatus        = "complete";
                            db.Entry(poitems).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception Ex)
                {
                    transaction.Rollback();
                    throw Ex;
                }
            }
            return(model);
        }
コード例 #9
0
        public ActionResult SharedEdit(/*[Bind(Include = "Name")]*/ Sharing entry, string action)
        {
            string currentUser = User.Identity.GetUserId();

            string currentUserEmail = User.Identity.GetUserName();


            bool isAllowed = db.Inventories.Where(inv => inv.Id == entry.InventoryId && (inv.UserId == currentUser || inv.SharedUsers.Any(s => s.Email == currentUserEmail && (s.Permission == AccessLevel.Edit || s.Permission == AccessLevel.Admin)))).Any();

            if (ModelState.IsValid && isAllowed)
            {
                db.Entry(entry).State = EntityState.Modified;
                db.SaveChanges();

                if (action == "SaveAndOpen")
                {
                    return(RedirectToAction("Open", "Inventories", new { id = entry.InventoryId }));
                }
                else
                {
                    return(RedirectToAction("Shared", "Inventories", new { inventoryid = entry.InventoryId }));
                }
            }

            return(View(entry));
        }
コード例 #10
0
 static void DeleteAllItems()
 {
     using (var db = new InventoryDbContext(_optionsBuilder.Options))
     {
         var items = db.Items.ToList();
         foreach (var item in items)
         {
             item.LastModifiedUserId = 1;
         }
         db.Items.RemoveRange(items);
         db.SaveChanges();
     }
 }
コード例 #11
0
        public ActionResult Create(User u)
        {
            string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(u.Password, "SHA1");

            if (ModelState.IsValid)
            {
                u.Password = pass;
                db.Users.Add(u);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
        }
コード例 #12
0
        public static void UpdateWardInventory(InventoryDbContext inventoryDbContext, List <DispatchItemsModel> dispatchItems)
        {
            try
            {
                if (dispatchItems != null)
                {
                    foreach (var stkItem in dispatchItems)
                    {
                        var wardItem = inventoryDbContext.WardStock.Where(i => i.ItemId == stkItem.ItemId && i.StockType == "inventory" && i.DepartmentId == stkItem.DepartmentId).FirstOrDefault();
                        if (wardItem != null)
                        {
                            wardItem.AvailableQuantity = wardItem.AvailableQuantity + Convert.ToInt32(stkItem.DispatchedQuantity);
                            inventoryDbContext.Entry(wardItem).State = EntityState.Modified;
                        }
                        else
                        {
                            var inventory = (from inv in inventoryDbContext.Stock
                                             join goods in inventoryDbContext.GoodsReceiptItems on inv.GoodsReceiptItemId equals goods.GoodsReceiptItemId
                                             where inv.ItemId == stkItem.ItemId
                                             select new
                            {
                                BatchNo = inv.BatchNO,
                                MRP = goods.ItemRate,
                                inv.ExpiryDate
                            }).FirstOrDefault();


                            WARDStockModel wardStock = new WARDStockModel();
                            wardStock.ItemId            = stkItem.ItemId;
                            wardStock.AvailableQuantity = Convert.ToInt32(stkItem.DispatchedQuantity);
                            wardStock.DepartmentId      = stkItem.DepartmentId;
                            wardStock.StockType         = "inventory";
                            if (inventory != null)
                            {
                                wardStock.BatchNo    = inventory.BatchNo;
                                wardStock.MRP        = Convert.ToDouble(inventory.MRP);
                                wardStock.ExpiryDate = inventory.ExpiryDate;
                            }
                            inventoryDbContext.WardStock.Add(wardStock);
                        }
                    }
                }

                //Update Stock records
                inventoryDbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #13
0
        public string CancelOrder(int OrderId)
        {
            var entityOrder = InventoryDbContext.Orders.SingleOrDefault(order => order.Id == OrderId);

            if (entityOrder == null)
            {
                return(null);
            }

            InventoryDbContext.Remove(entityOrder);
            InventoryDbContext.SaveChanges();

            return($"Order {OrderId} cancelled.");
        }
コード例 #14
0
ファイル: RentalService.cs プロジェクト: Elektri/Athene
        public void RentBook(string userId, int[] bookItemIds)
        {
            var bookItems = _db.BookItems
                            .Where(bi => bookItemIds.Contains(bi.Id))
                            .ToArray();
            var user = _userManager.FindByIdAsync(userId).Result;

            foreach (var bookItem in bookItems)
            {
                bookItem.RentedBy = user;
                bookItem.RentedAt = DateTime.Now;
            }
            _db.SaveChanges();
        }
コード例 #15
0
 static void UpdateItems()
 {
     using (var db = new InventoryDbContext(_optionsBuilder.Options))
     {
         var items = db.Items.ToList();
         foreach (var item in items)
         {
             item.LastModifiedUserId  = 1;
             item.CurrentOrFinalPrice = 9.99M;
         }
         db.Items.UpdateRange(items);
         db.SaveChanges();
     }
 }
コード例 #16
0
        public int UploadImageInDataBase(HttpPostedFileBase file, Item item)
        {
            item.Image = ConvertToBytes(file);
            var Content = new Item
            {
                Description = item.Description,
                Image       = item.Image
            };

            db.Entry(item).State = EntityState.Modified;
            db.SaveChanges();

            int i = db.SaveChanges();

            if (i == 1)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
コード例 #17
0
        public ActionResult SaveItems(Item item, int id)
        {
            var itemInDb = _context.Items.SingleOrDefault(i => i.Id == id);
            int Id       = 0;

            if (itemInDb != null)
            {
                Id = Convert.ToInt32(Session["UserId"]);
                itemInDb.Comments = item.Comments;
                itemInDb.Status   = item.Status;
                _context.SaveChanges();
            }

            return(RedirectToAction("Index", new{ Id }));
        }
コード例 #18
0
        public void RemoveSession()
        {
            //Acess database and enter session into database
            using (var db = new InventoryDbContext())
            {
                string SessionId = (string)Session["SessionId"];
                User   user      = db.users.Where(x => x.sessionId == SessionId).FirstOrDefault();

                user.sessionId       = null;
                Session["SessionId"] = null;

                //save changes
                db.SaveChanges();
            }
        }
コード例 #19
0
ファイル: RequestController.cs プロジェクト: sayAsoneELF/AIMS
 public ActionResult Delete(int id)
 {
     using (var context = new InventoryDbContext())
     {
         var result = context.Request.Where(x => x.RequestId.Equals(id)).FirstOrDefault();
         if (result != null)
         {
             context.Request.Remove(result);
             context.SaveChanges();
         }
     }
     return(new JsonResult {
         Data = "Successfully Deleted", JsonRequestBehavior = JsonRequestBehavior.AllowGet
     });
 }
コード例 #20
0
        public void AddOrderDetail(int ordId, int prdId, decimal qty)
        {
            UnitCost unitCost = new UnitCost();
            decimal  cost     = unitCost.GetUnitCost(prdId);

            context.OrderDetails.Add(new OrderDetail()
            {
                OrderId   = ordId,
                ProductId = prdId,
                Quantity  = qty,
                UnitPrice = 2,
                UnitCost  = cost
            });
            context.SaveChanges();
        }
コード例 #21
0
 //Update Stock records
 public static void UpdateStock(InventoryDbContext inventoryDbContext, List <StockModel> Stock)
 {
     try
     {
         foreach (var stkItem in Stock)
         {
             inventoryDbContext.Entry(stkItem).State = EntityState.Modified;
         }
         //Update Stock records
         inventoryDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #22
0
        public ApiResponse <IEnumerable <InventoryItem> > AddUpdate([FromBody] InventoryItem item)
        {
            item.LastUpdated = DateTime.Now;
            var existing = _context.Find <InventoryItem>(new object[] { item.ProductId });

            if (existing == null)
            {
                _context.Add(item);
            }
            else
            {
                existing.Quantity = item.Quantity;
            }
            _context.SaveChanges();
            return(GetAll());
        }
コード例 #23
0
 //this is used for ReturnToVendor
 //here we are updating only stock's available quantity
 public static void UpdateStockAvailQty(InventoryDbContext inventoryDbContext, List <StockModel> Stock)
 {
     try
     {
         foreach (var stkItem in Stock)
         {
             inventoryDbContext.Stock.Attach(stkItem);
             inventoryDbContext.Entry(stkItem).Property(x => x.AvailableQuantity).IsModified = true;
         }
         inventoryDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #24
0
 //Save all Write-Off items in database
 public static void AddretrnToVndrItems(InventoryDbContext inventoryDbContext, List <ReturnToVendorItemsModel> rtvItems)
 {
     try
     {
         foreach (var rtvItem in rtvItems)
         {
             rtvItem.CreatedOn = System.DateTime.Now;
             inventoryDbContext.ReturnToVendorItems.Add(rtvItem);
         }
         inventoryDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #25
0
 //Save all Write-Off items in database
 public static void AddWriteOffItems(InventoryDbContext inventoryDbContext, List <WriteOffItemsModel> writeOffItems)
 {
     try
     {
         foreach (var writeOfItem in writeOffItems)
         {
             inventoryDbContext.WriteOffItems.Add(writeOfItem);
         }
         //Save Dispatch Items
         inventoryDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #26
0
 //All the stock transaction save to database
 public static void AddStockTransaction(InventoryDbContext inventoryDbContext, List <StockTransactionModel> stockTransactions)
 {
     try
     {
         foreach (var stockTransactinItem in stockTransactions)
         {
             stockTransactinItem.CreatedOn = System.DateTime.Now;
             inventoryDbContext.StockTransactions.Add(stockTransactinItem);
         }
         //Save Stock Transactions
         inventoryDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #27
0
 //Save all Disaptch Items in database
 public static void AddDispatchItems(InventoryDbContext inventoryDbContext, List <DispatchItemsModel> dispatchItems)
 {
     try
     {
         foreach (var dispatchItem in dispatchItems)
         {
             dispatchItem.CreatedOn = System.DateTime.Now;
             inventoryDbContext.DispatchItems.Add(dispatchItem);
         }
         //Save Dispatch Items
         inventoryDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #28
0
 public ActionResult DeleteSupplier(int id, string sessionId)
 {
     if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
     {
         using (var db = new InventoryDbContext())
         {
             Suppliers ss = db.supplier.Where(x => x.supplierId == id).FirstOrDefault();
             db.supplier.Remove(ss);
             db.SaveChanges();
         }
         ViewData["staffname"] = userServices.getUserBySessionId(sessionId).employee.empName;
         return(RedirectToAction("SupplierList", new { sessionId }));
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
 }
コード例 #29
0
 public JsonResult DeclineRequest(int requestID, string status, string reasonForDeclining)
 {
     try
     {
         using (var context = new InventoryDbContext())
         {
             var eRequest = context.Request.FirstOrDefault(x => x.RequestId == requestID);
             eRequest.Status            = status;
             eRequest.ReasonForDeclined = reasonForDeclining;
             context.SaveChanges();//Save all changes
         }
     }
     catch (Exception ex)
     {
         return(Json(ex.ToString()));
     }
     return(Json(string.Empty));
 }
コード例 #30
0
        public ActionResult InsertSupplier(Suppliers s, string sessionId)
        {
            if (sessionId != null && userServices.getUserCountBySessionId(sessionId) == true)
            {
                using (var db = new InventoryDbContext())
                {
                    db.supplier.Add(s);
                    db.SaveChanges();
                }


                return(RedirectToAction("SupplierList", new { sessionId }));
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }