Beispiel #1
0
        // GET: InventoryItem/Edit/5
        public ActionResult Edit(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InventoryItem inventoryItem = db.InventoryItem.Find(id);

            if (inventoryItem == null)
            {
                return(HttpNotFound());
            }

            InventoryItemViewModel inventoryItemViewModel = new InventoryItemViewModel()
            {
                InventoryItemID = inventoryItem.InventoryItemID,
                Name            = inventoryItem.Name,
                Details         = inventoryItem.Details,
                SerialNumber    = inventoryItem.SerialNumber,
                SupplierID      = inventoryItem.SupplierID,
                CategoryID      = inventoryItem.CategoryID,
                Code            = inventoryItem.Code,
                PurchaseDate    = inventoryItem.PurchaseDate,
                GuaranteeID     = inventoryItem.GuaranteeID
            };

            ViewBag.SupplierID  = new SelectList(db.Client, "ClientID", "Name", inventoryItemViewModel.SupplierID);
            ViewBag.CategoryID  = new SelectList(db.InventoryCategory, "InventoryCategoryID", "Name", inventoryItemViewModel.CategoryID);
            ViewBag.GuaranteeID = new SelectList(db.ItemGuarantee, "ItemGuaranteeID", "Name", inventoryItemViewModel.GuaranteeID);
            return(View(inventoryItemViewModel));
        }
        public async virtual Task <ActionResult> Edit(string id, InventoryItemViewModel model, HttpPostedFileBase imageFile)
        {
            try
            {
                // TODO: Add update logic here
                InventoryItem newInventoryItem = new InventoryItem();
                UpdateModel(newInventoryItem);
                string inventoryItemId = await InventoryManager.UpdateInventoryItem(newInventoryItem);

                if (imageFile != null)
                {
                    DeleteImageFile(string.Format("{0}{1}", id, model.ImageExtension));
                    string imgExt = UploadImageFile(imageFile, newInventoryItem.Id);
                    newInventoryItem.ImageExtension = imgExt;
                    await InventoryManager.UpdateInventoryItem(newInventoryItem);
                }

                await InventoryManager.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = e.Message;
                return(View(model));
            }
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "InventoryItemID,Name,Details,SerialNumber,SupplierID,CategoryID,Code,PurchaseDate,GuaranteeID")] InventoryItemViewModel inventoryItemViewModel)
        {
            if (ModelState.IsValid)
            {
                InventoryItem inventoryItem = new InventoryItem();

                inventoryItem.InventoryItemID = inventoryItemViewModel.InventoryItemID;
                inventoryItem.Name            = inventoryItemViewModel.Name;
                inventoryItem.Details         = inventoryItemViewModel.Details;
                inventoryItem.SerialNumber    = inventoryItemViewModel.SerialNumber;
                inventoryItem.SupplierID      = inventoryItemViewModel.SupplierID;
                inventoryItem.CategoryID      = inventoryItemViewModel.CategoryID;
                inventoryItem.Code            = inventoryItemViewModel.Code;
                inventoryItem.PurchaseDate    = inventoryItemViewModel.PurchaseDate;
                inventoryItem.GuaranteeID     = inventoryItemViewModel.GuaranteeID;

                db.InventoryItem.Add(inventoryItem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SupplierID  = new SelectList(db.Client, "ClientID", "Name", inventoryItemViewModel.SupplierID);
            ViewBag.CategoryID  = new SelectList(db.InventoryCategory, "InventoryCategoryID", "Name", inventoryItemViewModel.CategoryID);
            ViewBag.GuaranteeID = new SelectList(db.ItemGuarantee, "ItemGuaranteeID", "Name", inventoryItemViewModel.GuaranteeID);

            return(View(inventoryItemViewModel));
        }
Beispiel #4
0
        public async Task <IHttpActionResult> Post(string categoryMoniker, InventoryItemViewModel model)
        {
            try
            {
                if (await _itemRespository.CheckItemMonikerExist(model.Moniker))
                {
                    ModelState.AddModelError("Item", $"Item moniker '{model.Moniker}' already in use.");
                }

                if (ModelState.IsValid)
                {
                    var item = _mapper.Map <InventoryItem>(model);

                    _itemRespository.AddItem(item);
                    if (await _itemRespository.SaveContextChangesAsync())
                    {
                        var newItem = _mapper.Map <InventoryItemViewModel>(item);
                        return(CreatedAtRoute("GetItems", new { categoryMoniker }, newItem));
                    }
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
            return(BadRequest(ModelState));
        }
Beispiel #5
0
        //adds a category item not currently present in inventory tree cause it didn't have children to show

        private int AddNonExistentCategory(Category category, ObservableCollection <InventoryItemViewModel> inventoryItems)
        {
            //"No Category" category
            if (category == null)
            {
                InventoryItemViewModel categoryRowToAdd = new InventoryItemViewModel(0, "Sin Categoría", 0, InventoryItemType.Category);
                return(InsertAlphabetical(categoryRowToAdd, inventoryItems));
            }
            else
            {
                Category parentCategory = category.ParentCategory;

                InventoryItemViewModel categoryRowToAdd;

                //IS ROOT CATEGORY
                if (parentCategory == null)
                {
                    categoryRowToAdd = new InventoryItemViewModel(category, 0);
                    return(InsertAlphabetical(categoryRowToAdd, inventoryItems));
                }
                else
                {
                    //CHECK IF PARENT EXISTS
                    int parentCategoryIndex = FindCategoryIndex(parentCategory.Id, inventoryItems);

                    if (parentCategoryIndex == -1)
                    {
                        parentCategoryIndex = AddNonExistentCategory(parentCategory, inventoryItems);
                    }

                    categoryRowToAdd = new InventoryItemViewModel(category, inventoryItems[parentCategoryIndex].Level + 1);
                    return(InsertAlphabetical(categoryRowToAdd, inventoryItems, parentCategoryIndex));
                }
            }
        }
        public void Update(InventoryItemViewModel item)
        {
            InventoryItem inventory = _mapper.Map <InventoryItem>(item);

            _inventoryRepository.Update(inventory);
            _inventoryRepository.SaveChanges();
        }
        public IActionResult Create()
        {
            var inventoryItem = new InventoryItemViewModel {
            };

            return(View(inventoryItem));
        }
Beispiel #8
0
        private int AddInventoryItemChildren(Category parentCategory, int parentLevel, ObservableCollection <InventoryItemViewModel> inventoryItems, Predicate <Product> filter)
        {
            int productCounter = 0;

            foreach (var item in parentCategory.ChildrenCategories.OrderBy(x => x.Name))
            {
                InventoryItemViewModel catItem = new InventoryItemViewModel(item, parentLevel + 1);

                inventoryItems.Add(catItem);

                int childrenCount = AddInventoryItemChildren(item, parentLevel + 1, inventoryItems, filter);

                if (childrenCount == 0)
                {
                    inventoryItems.Remove(catItem);
                }

                productCounter += childrenCount;
            }

            foreach (var item in parentCategory.Products.OrderBy(x => x.Name))
            {
                InventoryItemViewModel prodItem = new InventoryItemViewModel(item, parentLevel + 1);

                if (filter(item))
                {
                    inventoryItems.Add(prodItem);
                    productCounter++;
                }
            }

            return(productCounter);
        }
        public IActionResult Create(InventoryItemViewModel inventoryItemViewModel)
        {
            if (ModelState.IsValid)
            {
                if (inventoryItemViewModel.InventoryItem.ItemQuantity > 5)
                {
                    var model = CreateInventoryItemViewModel(inventoryItemViewModel.InventoryItem,
                                                             "Max Quantity for an item is 5. please try again Later");
                    return(View(model));
                }
                else if (InventoryItemRepository.GetTotalQuantity() > 200)
                {
                    var model = CreateInventoryItemViewModel(inventoryItemViewModel.InventoryItem,
                                                             $"Your current limit of adding item is exceeded, you can add {200- InventoryItemRepository.GetTotalQuantity()} items only");
                    return(View(model));
                }
                else
                {
                    var inventoryitem = InventoryItemRepository.GetInventoryItem(inventoryItemViewModel.InventoryItem.ItemName);
                    if (inventoryitem != null)
                    {
                        var model = CreateInventoryItemViewModel(inventoryItemViewModel.InventoryItem,
                                                                 "Item name already exists try again with some other name");
                        return(View(model));
                    }

                    InventoryItemRepository.AddNewItem(inventoryItemViewModel.InventoryItem);
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(View(inventoryItemViewModel));
        }
        public InventoryItemViewModel GetProductViewModel(string path, string id)
        {
            var message = GetTestPayload(path);
            var product = message.Product;
            var vm      = new InventoryItemViewModel {
                ProductDetailsModel = MapProduct(product),
                BaseClasses         = GetBaseClasses(),
                SpecificationTypes  = GetSpecificationTypes().OrderBy(c => c.Name).ToList(),
                UnitTypes           = GetUnitTypes().OrderBy(c => c.Name).ToList(),
                PriceTypes          = GetPriceTypes().OrderBy(c => c.Name).ToList(),
                ColorTypes          = GetColorTypes().OrderBy(c => c.Name).ToList(),
                ActivityTypes       = GetActivityTypes().OrderBy(c => c.Name).ToList()
            };

            vm.SelectedClass = GetSelectedClass(vm.BaseClasses, product.Class.Value);
            vm.CurrentProductDetailsModel = new ProductDetailsModel();
            var displayName = GetIdentifierValue(product, "Display Name");

            vm.NavigationItems = new List <NavigationItem> {
                new NavigationItem {
                    Id          = vm.ProductDetailsModel.Id,
                    DisplayName = vm.ProductDetailsModel.DisplayName
                }
            };
            return(vm);
        }
        public async virtual Task <ActionResult> Create(InventoryItemViewModel model, HttpPostedFileBase imageFile)
        {
            try
            {
                // TODO: Add insert logic here
                var exist = await InventoryManager.GetInventoryList();

                if (exist.Any(x => x.ProductCode == model.ProductCode))
                {
                    throw new Exception("Product ID already exist!");
                }


                InventoryItem newInventoryItem = new InventoryItem();
                UpdateModel(newInventoryItem);
                string inventoryItemId = await InventoryManager.AddNewInventoryItem(newInventoryItem);

                if (imageFile != null)
                {
                    string imgExt = UploadImageFile(imageFile, inventoryItemId);
                    newInventoryItem.ImageExtension = imgExt;
                    await InventoryManager.AddNewInventoryItem(newInventoryItem);
                }

                await InventoryManager.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = e.Message;
                return(RedirectToAction("Index"));
                //                return View();
            }
        }
        public IActionResult Create()
        {
            var model = new InventoryItemViewModel();

            model.Categories    = InventoryItemRepository.GetCategoryList();
            model.InventoryItem = new InventoryItem();
            return(View(model));
        }
        public InventoryItemViewModel CreateInventoryItemViewModel(InventoryItem inventoryItem, string ErrorMessage)
        {
            var model = new InventoryItemViewModel();

            model.Categories    = InventoryItemRepository.GetCategoryList();
            model.InventoryItem = inventoryItem;
            model.ErrorMessage  = ErrorMessage;
            return(model);
        }
Beispiel #14
0
        public IActionResult Create()
        {
            var inventoryItem = new InventoryItemViewModel {
            };

            ViewData["ItemTypes"] = GetItemTypes();

            return(View(inventoryItem));
        }
Beispiel #15
0
        public ActionResult <int> Post([FromBody] InventoryItemViewModel value)
        {
            InventoryItem item = new InventoryItem();

            item.Column    = value.Column;
            item.ProductId = value.ProductId;
            item.Qty       = value.Qty;
            item.Row       = value.Row;
            return(_db.AddInventoryItem(item));
        }
        public async Task <ActionResult> Edit(string id, InventoryItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _inventoryRepo.UpdateInventoryItem(id, model);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
        public InventoryItemViewModel Find(int id)
        {
            InventoryItemViewModel inventory = _mapper.Map <InventoryItemViewModel>(_inventoryRepository.Find(id));

            if (inventory != null)
            {
                inventory.AvailableQuantity = GetAvailableProductQuantity(id);
            }

            return(inventory);
        }
Beispiel #18
0
        public ActionResult <bool> Put(int id, [FromBody] InventoryItemViewModel value)
        {
            InventoryItem item = new InventoryItem();

            item.Id        = id;
            item.Column    = value.Column;
            item.ProductId = value.ProductId;
            item.Qty       = value.Qty;
            item.Row       = value.Row;
            return(_db.UpdateInventoryItem(item));
        }
        public async Task <IActionResult> Create(InventoryItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.CreatedBy = User.FindFirstValue(ClaimTypes.NameIdentifier);

                await _inventoryRepo.CreateInventoryItem(model);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
Beispiel #20
0
        private int InsertAlphabetical(InventoryItemViewModel invItem, ObservableCollection <InventoryItemViewModel> inventoryItems, int parentIndex = -1)
        {
            int mylevel = parentIndex == -1 ? 0 : inventoryItems[parentIndex].Level + 1;

            int i;

            for (i = parentIndex + 1; i < inventoryItems.Count; i++)
            {
                InventoryItemViewModel currentItem = inventoryItems[i];

                //ignore items deeper in the tree
                if (currentItem.Level > mylevel)
                {
                    continue;
                }

                //category children ends
                if (currentItem.Level < mylevel)
                {
                    break;
                }

                //insert categories before products
                if (invItem.ItemType == InventoryItemType.Category && currentItem.ItemType == InventoryItemType.Product)
                {
                    break;
                }

                //and products after categories
                if (invItem.ItemType == InventoryItemType.Product && currentItem.ItemType == InventoryItemType.Category)
                {
                    continue;
                }

                if (currentItem.Name.CompareTo(invItem.Name) > 0)
                {
                    break;
                }
            }

            if (i == inventoryItems.Count)
            {
                inventoryItems.Add(invItem);
            }
            else
            {
                inventoryItems.Insert(i, invItem);
            }

            return(i);
        }
Beispiel #21
0
        public static void UpdateInventoryItemEdit(this InventoryItem inventoryItem, InventoryItemViewModel inventoryItemVm)
        {
            inventoryItem.Name            = inventoryItemVm.Name;
            inventoryItem.ItemDescription = inventoryItemVm.ItemDescription;
            inventoryItem.Quantity        = inventoryItemVm.Quantity;
            inventoryItem.Price           = inventoryItemVm.Price;

            inventoryItem.PriceDate        = inventoryItemVm.PriceDate;
            inventoryItem.VendorId         = inventoryItemVm.VendorId;
            inventoryItem.UnitId           = inventoryItemVm.UnitId;
            inventoryItem.CategoryId       = inventoryItemVm.CategoryId;
            inventoryItem.IngredientTypeId = 39;
            inventoryItem.UpdatedDate      = DateTime.Now;
        }
Beispiel #22
0
        public async Task <ActionResult> Edit(string id, InventoryItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.CreatedBy = User.FindFirstValue(ClaimTypes.NameIdentifier);
                await _inventoryRepo.UpdateInventoryItem(id, model);

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["ItemTypes"] = GetItemTypes();

            return(View(model));
        }
Beispiel #23
0
        //public int CreateInventoryTree(ObservableCollection<TreeNodeViewModel> prodTypeNodes, Predicate<Product> filter)
        //{
        //    prodTypeNodes.Clear();

        //    int count = 0;

        //    using (var context = new RestaurantDBEntities())
        //    {
        //        //start with root categories
        //        var query = from c in context.Categories
        //                    where c.ParentCategory == null
        //                    orderby c.Name
        //                    select c;

        //        foreach (var item in query)
        //        {
        //            CategoryNode cn = new CategoryNode();
        //            cn.Id = item.Id;
        //            cn.Name = item.Name;

        //            var children_count = AddChildrenTree(cn, item, filter);

        //            //don't show categories without child products
        //            if (children_count > 0)
        //            {
        //                prodTypeNodes.Add(cn);

        //                count += children_count;
        //            }
        //        }

        //        var pQuery = from p in context.Products
        //                     where p.Category == null
        //                     orderby p.Name
        //                     select p;

        //        //products without category
        //        CategoryNode uncategorized = new CategoryNode();
        //        uncategorized.Id = 0;
        //        uncategorized.Name = "Sin Categoría";

        //        foreach (var item in pQuery)
        //        {
        //            if (!filter(item)) continue;

        //            ProductNode pn = new ProductNode();
        //            pn.Id = item.Id;
        //            pn.Name = item.Name;

        //            pn.Parent = uncategorized;
        //            uncategorized.Children.Add(pn);
        //        }

        //        if (uncategorized.Children.Count > 0)
        //        {
        //            prodTypeNodes.Add(uncategorized);
        //            count += uncategorized.Children.Count;
        //        }
        //    }

        //    return count;
        //}

        //private int AddChildrenTree(CategoryNode parentNode, Category parentOriginal, Predicate<Product> filter)
        //{
        //    int count = 0;

        //    var childrenCategories = from c in parentOriginal.ChildrenCategories
        //                             orderby c.Name
        //                             select c;

        //    foreach (var item in childrenCategories)
        //    {
        //        CategoryNode cn = new CategoryNode();
        //        cn.Id = item.Id;
        //        cn.Name = item.Name;

        //        var children_count = AddChildrenTree(cn, item, filter);

        //        //don't show categories without child products
        //        if (children_count > 0)
        //        {
        //            cn.Parent = parentNode;
        //            parentNode.Children.Add(cn);

        //            count += children_count;
        //        }
        //    }

        //    var childrenProducts = from p in parentOriginal.Products
        //                           orderby p.Name
        //                           select p;

        //    foreach (var item in childrenProducts)
        //    {
        //        if (!filter(item)) continue;

        //        ProductNode pn = new ProductNode();
        //        pn.Id = item.Id;
        //        pn.Name = item.Name;

        //        pn.Parent = parentNode;
        //        parentNode.Children.Add(pn);

        //        count++;
        //    }

        //    return count;
        //}

        #endregion

        #region Add-Remove Product Items

        public void AddProductItem(Product p, ObservableCollection <InventoryItemViewModel> inventoryItems)
        {
            int parentCategoryId = p.Category == null ? 0 : p.Category.Id;

            int parentIndex = FindCategoryIndex(parentCategoryId, inventoryItems);

            if (parentIndex == -1)
            {
                parentIndex = AddNonExistentCategory(p.Category, inventoryItems);
            }

            InventoryItemViewModel proditem = new InventoryItemViewModel(p, inventoryItems[parentIndex].Level + 1);

            InsertAlphabetical(proditem, inventoryItems, parentIndex);
        }
        public void Add(InventoryItemViewModel inventoryViewModel)
        {
            InventoryItem inventory = _mapper.Map <InventoryItem>(inventoryViewModel);

            for (int i = 0; i < inventoryViewModel.Quantity; i++)
            {
                _inventoryRepository.Add(new InventoryItem {
                    ProductId             = inventoryViewModel.ProductId,
                    RegistrationDate      = inventoryViewModel.RegistrationDate,
                    InventoryItemStatusId = (int)InventoryItemStatusType.Available
                });
            }

            _inventoryRepository.SaveChanges();
        }
Beispiel #25
0
        public async Task <ActionResult> Details(string id)
        {
            if (id == null)
            {
                return(new BadRequestResult());
            }

            InventoryItemViewModel inventoryItem = await _inventoryRepo.GetInventoryItem(id);

            if (inventoryItem == null)
            {
                return(NotFound());
            }

            return(View(inventoryItem));
        }
        private List <InventoryItemViewModel> GetInventoryItemViewModel(IEnumerable <InventoryItem> items)
        {
            List <InventoryItemViewModel> lstItems = new List <InventoryItemViewModel>();

            foreach (var item in items)
            {
                InventoryItemViewModel inventoryItemvm = new InventoryItemViewModel();
                inventoryItemvm.Id           = item.Id;
                inventoryItemvm.Name         = item.Name;
                inventoryItemvm.Price        = item.Price;
                inventoryItemvm.Manufacturer = item.Manufacturer;

                lstItems.Add(inventoryItemvm);
            }
            return(lstItems);
        }
        public async Task <InventoryItemViewModel> GetInventoryByProviderInventoryId(int providerId, string inventoryId)
        {
            InventoryItemViewModel model = new InventoryItemViewModel();

            try
            {
                model = await(from i in _legacyContext.Inventories
                              where i.inventoryid == inventoryId && i.ownerid == providerId
                              select new InventoryItemViewModel
                {
                    BedroomSize         = i.bedrooms.ToString(),
                    CheckInDate         = i.fdate,
                    CheckOutDate        = i.tdate,
                    InventoryId         = i.keyid,
                    InventoryType       = i.inventorytype.Trim(),
                    KitchenType         = i.kitchentype.Trim(),
                    MaxGuests           = i.maxguests,
                    Privacy             = i.adults,
                    ProviderInventoryId = i.inventoryid,
                    Quantity            = i.quantity - i.hold,
                    UnitId  = i.unitkeyid,
                    NetRate = decimal.Parse(i.rsicost)
                }).FirstOrDefaultAsync();
                if (model != null)
                {
                    model.Message = "Success";
                }
                else
                {
                    model.Message = "Error: Inventory not found";
                }

                model.Message = "Success";
            }
            catch (Exception ex)
            {
                if (model == null)
                {
                    model = new InventoryItemViewModel();
                }

                model.Message = $"Error: {ex.Message}";
            }

            return(model);
        }
        //
        // GET: /Admin/Inventory/Edit/5
        public async virtual Task <ActionResult> Edit(string id)
        {
            InventoryItem newInventoryItem = await InventoryManager.GetInventoryItem(id);

            InventoryItemViewModel model = new InventoryItemViewModel
            {
                Id             = newInventoryItem.Id,
                Color          = newInventoryItem.Color,
                QtyInStock     = newInventoryItem.QtyInStock,
                Description    = newInventoryItem.Description,
                ProductCode    = newInventoryItem.ProductCode,
                ImageExtension = newInventoryItem.ImageExtension,
                MyCode         = newInventoryItem.MyCode
            };

            return(View(model));
        }
Beispiel #29
0
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new BadRequestResult());
            }

            InventoryItemViewModel inventoryItem = await _inventoryRepo.GetInventoryItem(id);

            if (inventoryItem == null)
            {
                return(NotFound());
            }

            ViewData["ItemTypes"] = GetItemTypes();

            return(View(inventoryItem));
        }
        public async Task CreateInventoryItem(InventoryItemViewModel model)
        {
            var inventoryRecord = new InventoryItems
            {
                Id              = Guid.NewGuid().ToString(),
                Name            = model.Name,
                ItemDescription = model.ItemDescription,
                CreatedBy       = model.CreatedBy,
                ModifiedOn      = DateTime.Now,
                IsSoldOut       = model.IsSoldOut,
                ItemType        = model.ItemType,
                ItemPrice       = model.ItemPrice,
                ItemQuantity    = model.ItemQuantity
            };

            _dbContext.InventoryItems.Add(inventoryRecord);

            await _dbContext.SaveChangesAsync();
        }