Esempio n. 1
0
        public ActionResult Create(Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                inventory.CompanyId = CurrentUser.CompanyId;
                inventory.AddedBy = CurrentUser.UserId;
                inventory.RemainingQuantity = inventory.OriginalQuantity;
                inventory.CreationDate = DateTime.Now;

                using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
                {
                    if(inventoryRepository.Create(inventory))
                        return RedirectToAction("Index");
                    return Error(Loc.Dic.Error_DatabaseError);
                }

            }

            //using (OrderItemsRepository orderItemsRepository = new OrderItemsRepository())
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            //using (InventoryRepository inventoryRepository = new InventoryRepository())
            {
                //ViewBag.RelatedInventoryItem = new SelectList(orderItemsRepository.GetList(), "Id", "Title" + "SubTitle");
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId), "Id", "Name");
            }
            return View(inventory);
        }
Esempio n. 2
0
        public ActionResult Create(Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                inventory.CompanyId         = CurrentUser.CompanyId;
                inventory.AddedBy           = CurrentUser.UserId;
                inventory.RemainingQuantity = inventory.OriginalQuantity;
                inventory.CreationDate      = DateTime.Now;

                using (InventoryRepository inventoryRepository = new InventoryRepository(CurrentUser.CompanyId))
                {
                    if (inventoryRepository.Create(inventory))
                    {
                        return(RedirectToAction("Index"));
                    }
                    return(Error(Loc.Dic.Error_DatabaseError));
                }
            }

            //using (OrderItemsRepository orderItemsRepository = new OrderItemsRepository())
            using (LocationsRepository locationsRepository = new LocationsRepository(CurrentUser.CompanyId))
            //using (InventoryRepository inventoryRepository = new InventoryRepository())
            {
                //ViewBag.RelatedInventoryItem = new SelectList(orderItemsRepository.GetList(), "Id", "Title" + "SubTitle");
                ViewBag.LocationId = new SelectList(locationsRepository.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId), "Id", "Name");
            }
            return(View(inventory));
        }
Esempio n. 3
0
 public ActionResult AddInventory(InventoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         InventoryRepository inventoryRepository = new InventoryRepository(new ApplicationDbContext());
         inventoryRepository.Create(model);
         return RedirectToAction("Inventories");
     }
     return View(model);
 }
Esempio n. 4
0
 public ActionResult AddInventory(InventoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         InventoryRepository inventoryRepository = new InventoryRepository(new ApplicationDbContext());
         inventoryRepository.Create(model);
         return(RedirectToAction("Inventories"));
     }
     return(View(model));
 }
Esempio n. 5
0
 public ActionResult Post([FromBody] Inventory value)
 {
     try
     {
         return(Ok(_repo.Create(value)));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Esempio n. 6
0
        public IActionResult Create([Required][FromBody] CreateInventoryDto product)
        {
            try
            {
                var result = _repo.Create(product);

                return(StatusCode((int)HttpStatusCode.Created, result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 7
0
        public virtual async Task <InventoryModel> createInventoryAsync(InventoryModel inventoryModel)
        {
            Inventory inventory = new Inventory();

            inventory.AvailableQuantity  = inventoryModel.AvailableQuantity;
            inventory.Barcode            = inventoryModel.Barcode;
            inventory.Height             = inventoryModel.Height;
            inventory.InventoryName      = inventoryModel.InventoryName;
            inventory.Stock_Keeping_Unit = inventoryModel.Stock_Keeping_Unit;
            inventory.Weight             = inventoryModel.Weight;
            inventory.Price            = inventoryModel.Price;
            inventory.ImageInventoryId = inventoryModel.ImageInventoryId;
            inventory.isActive         = true;
            inventory.CreatedBy        = 1;
            inventory.ModifiedBy       = 1;
            inventory.CreationDate     = DateTime.Now;
            inventory.ModificationDate = DateTime.Now;
            _inventoryRepository.Create(inventory);
            await _inventoryRepository.SaveAsync();

            InventoryModel inventoryModelData = Mapper.Map <Inventory, InventoryModel>(inventory);

            return(inventoryModelData);
        }
Esempio n. 8
0
        public ActionResult AddToInventory(AddToInventoryModel model)
        {
            if (!Authorized(RoleType.InventoryManager)) return Error(Loc.Dic.error_no_permission);

            Order order;
            List<Inventory> createdItems = new List<Inventory>();
            List<Location> locations;
            bool noCreationErrors = true;

            using (InventoryRepository inventoryRep = new InventoryRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRep.GetEntity(model.OrderId, "Supplier", "Orders_OrderToItem", "Orders_OrderToItem.Orders_Items");

                if (order == null) return Error(Loc.Dic.error_order_get_error);
                if (order.WasAddedToInventory) return Error(Loc.Dic.error_order_was_added_to_inventory);
                if (order.StatusId < (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport) return Error(Loc.Dic.error_invoice_not_scanned_and_approved);

                locations = locationsRep.GetList().ToList();
                if (locations == null || locations.Count == 0) return Error(Loc.Dic.error_no_locations_found);

                foreach (SplittedInventoryItem splitedItem in model.InventoryItems)
                {
                    if (!noCreationErrors) break;
                    if (!splitedItem.AddToInventory) continue;

                    int? itemId = splitedItem.ItemsToAdd[0].ItemId;
                    Orders_OrderToItem originalItem = order.Orders_OrderToItem.FirstOrDefault(x => x.Id == itemId);
                    bool isValidList = originalItem != null && splitedItem.ItemsToAdd.All(x => x.ItemId == itemId);

                    if (!isValidList) { noCreationErrors = false; break; }

                    if (splitedItem.ItemsToAdd.Count == 1)
                    {
                        Inventory listItem = splitedItem.ItemsToAdd[0];
                        if (!locations.Any(x => x.Id == listItem.LocationId)) return Error(Loc.Dic.error_invalid_form);

                        Inventory newItem = new Inventory()
                        {
                            AssignedTo = listItem.AssignedTo,
                            LocationId = listItem.LocationId,
                            Notes = listItem.Notes,
                            SerialNumber = listItem.SerialNumber,
                            Status = listItem.Status,
                            WarrentyPeriodStart = listItem.WarrentyPeriodStart,
                            WarrentyPeriodEnd = listItem.WarrentyPeriodEnd,
                            ItemId = originalItem.ItemId,
                            OrderId = order.Id,
                            CompanyId = CurrentUser.CompanyId,
                            IsOutOfInventory = false,
                            OriginalQuantity = originalItem.Quantity,
                            RemainingQuantity = originalItem.Quantity
                        };

                        if (!inventoryRep.Create(newItem)) { noCreationErrors = false; break; }
                        createdItems.Add(newItem);
                    }
                    else if (originalItem.Quantity == splitedItem.ItemsToAdd.Count)
                    {
                        foreach (var item in splitedItem.ItemsToAdd)
                        {
                            if (!locations.Any(x => x.Id == item.LocationId)) { noCreationErrors = false; break; }

                            item.ItemId = originalItem.ItemId;
                            item.OrderId = order.Id;
                            item.CompanyId = CurrentUser.CompanyId;
                            item.IsOutOfInventory = false;

                            if (!inventoryRep.Create(item)) { noCreationErrors = false; break; }
                            createdItems.Add(item);
                        }
                    }
                    else { noCreationErrors = false; break; }
                }

                if (!noCreationErrors)
                {
                    foreach (var item in createdItems)
                    {
                        inventoryRep.Delete(item.Id);
                    }

                    return Error(Loc.Dic.error_inventory_create_error);
                }

                order.WasAddedToInventory = true;
                order.LastStatusChangeDate = DateTime.Now;
                if (ordersRep.Update(order) == null) return Error(Loc.Dic.error_database_error);

                bool hasInventoryItems = model.InventoryItems.Any(x => x.AddToInventory);
                string notes = hasInventoryItems ? Loc.Dic.AddToInventory_with_inventory_items : Loc.Dic.AddToInventory_no_inventory_items;

                int? historyActionId = null;
                historyActionId = (int)HistoryActions.AddedToInventory;
                Orders_History orderHistory = new Orders_History();
                using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, order.Id))
                    if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value, notes);

                return RedirectToAction("PendingInventory");
            }
        }
Esempio n. 9
0
 public Inventory Create(Inventory entity)
 => _inventoryRepository.Create(entity);