private void UpdateStockItemAmount(StockItemViewModel item)
 {
     if (!resetAmount)
     {
         if (item.Amount >= 0)
         {
             List <TransactionItem> items = new List <TransactionItem>();
             TransactionItem        i     = new TransactionItem()
             {
                 ProductId      = item.ProductId,
                 QuantityChange = item.Amount - item.StartingAmount
             };
             items.Add(i);
             if (DbManager.GetInstance().RegisterQuantityChangeInStock(items, _CurrentStockId))
             {
                 MessageBox.Show("Updated stock item in database");
             }
             else
             {
                 MessageBox.Show("Could not update stock item in database");
             }
         }
         else
         {
             resetAmount = true;
             item.Amount = item.StartingAmount;
             MessageBox.Show("Please enter a positive value");
         }
     }
     else
     {
         resetAmount = false;
     }
 }
        public ActionResult Create()
        {
            StockItemViewModel svm = new StockItemViewModel();

            svm.Suppliers = _unitOfWork.Suppliers.GetAll().ToList();
            return(View(svm));
        }
예제 #3
0
        public IActionResult AddToCart(int countin)
        {
            /// <summary>
            /// Adds order item view model to cart
            /// </summary>
            Customer           thisCustomer = (Customer)_cache.Get("thisCustomer");
            StockItemViewModel vSt          = (StockItemViewModel)_cache.Get("currentViewedStock");

            if (!UtilMethods.CheckProductCount(vSt.LocationId, vSt.ProductId, countin, _context))
            {
                StockItemViewModel thisSIVM = (StockItemViewModel)_cache.Get("currentViewedStock");
                return(Redirect($"/Home/ProductSelect?locid={thisSIVM.LocationId}&prodid={thisSIVM.ProductId}&ovarload=true"));
            }
            double             totalPrice = vSt.Price * countin;
            OrderItemViewModel thisOrder  = new OrderItemViewModel(
                thisCustomer.CustomerId,
                vSt.LocationId,
                vSt.ProductId,
                $"{thisCustomer.FirstName} {thisCustomer.LastName}",
                vSt.ProductName,
                countin,
                UtilMethods.TrimPriceDigits(totalPrice),
                vSt.LocationAddress,
                DateTime.Now);
            List <OrderItemViewModel> CurrentCart = (List <OrderItemViewModel>)_cache.Get("customerCart");

            CurrentCart.Add(thisOrder);
            _cache.Set("customerCart", CurrentCart);
            return(Redirect("/Home/Cart"));
        }
        public void BuildStockItemViewModelFromLocStockWorks()
        {
            // Act
            //// Service setup
            var services = new ServiceCollection();

            services.AddMemoryCache();
            services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb"));
            var serviceProvider = services.BuildServiceProvider();
            //// DbContext setup
            DbContextClass testContext = serviceProvider.GetService <DbContextClass>();
            //// DbContext populating
            Location  testLocation  = new Location();
            StockItem testStockItem = new StockItem();

            testStockItem.DiscountPercent = 50;
            Product testProduct = new Product();

            testProduct.BasePrice = 6;
            testContext.Add(testProduct);
            testContext.SaveChanges();
            // Arrange
            StockItemViewModel testStockItemViewModel = RevatureP1.UtilMethods.BuildStockItemViewModelFromLocStock(
                testLocation, testStockItem, testContext);
            var resultVal   = testStockItemViewModel.SaleString;
            var expectedVal = "50% Off!";

            //Assert
            Assert.Equal(expectedVal, resultVal);
        }
예제 #5
0
        public async Task <IHttpActionResult> CreateStockTransaction(StockItemViewModel stockItem)
        {
            if (!ModelState.IsValid)
            {
                foreach (var v in ModelState.Values)
                {
                    foreach (var e in v.Errors)
                    {
                        if (e.Exception != null)
                        {
                            return
                                (BadRequest(
                                     "Something went wrong. Please check your form fields for disallowed or missing values."));
                        }
                    }
                }

                return(BadRequest(ModelState));
            }

            if (stockItem.StockItemQuantity == 0)
            {
                return(BadRequest("You can't add a quantity of 0."));
            }

            var stockTransaction = new StockTransaction
            {
                StockTransactionItem     = db.StockItems.FirstOrDefault(g => g.StockItemGuid == stockItem.StockItemGuid),
                StockTransactionDate     = DateTime.Now,
                StockTransactionGuid     = Guid.NewGuid(),
                StockTransactionQuantity = stockItem.StockItemQuantity,
                StockTransactionUser     = UserManager().FindById(User.Identity.GetUserId()),
                StockTransactionOrder    =
                    stockItem.Order == null
                        ? null
                        : await db.Orders.FirstOrDefaultAsync(g => g.OrderGuid == stockItem.Order.OrderGuid),
                StockTransactionSupply =
                    stockItem.Supply == null
                        ? null
                        : await db.Supplys.FirstOrDefaultAsync(g => g.SupplyGuid == stockItem.Supply.SupplyGuid)
            };

            db.StockTransactions.Add(stockTransaction);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (StockExists(stockTransaction.StockTransactionItem.StockItemStock.StockGuid))
                {
                    return(Conflict());
                }
                throw;
            }

            return(CreatedAtRoute("DefaultApi", new { id = stockTransaction.StockTransactionGuid }, stockTransaction));
        }
        // GET: SaleSlips/Details/5
        public ActionResult Details(int id)
        {
            var st = new StockItemViewModel()
            {
                Stocks = db.Stocks.Find(id),
                //StockItems=db.StockItems.Where(s=>s.StockId== id).ToList()
            };

            return(View(st));
        }
 private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName.Equals("Amount"))
     {
         StockItemViewModel item = sender as StockItemViewModel;
         if (item != null)
         {
             UpdateStockItemAmount(item);
         }
     }
 }
예제 #8
0
        // POST: api/Employee
        public StockItemViewModel Post([FromBody] StockItemViewModel value)
        {
            var employee = StockItem.Create(
                value.Name,
                value.Quantity,
                value.SellingPrice,
                value.CostPrice
                );

            repository.Insert(employee);
            return(Mapper.Map <StockItemViewModel>(employee));
        }
        public static StockItemViewModel BuildStockItemViewModelFromLocStock(Location thisLocation, StockItem thisStockItem, DbContextClass context)
        {
            /// <summary>
            /// Builds a stock item view model from location and stock item
            /// </summary>
            Product thisProduct         = UtilMethods.GetProductById(thisStockItem.ProductId, context);
            double  thisDiscountPercent = thisStockItem.DiscountPercent;
            double  thisPrice           = UtilMethods.GetDiscountedPrice(thisProduct, thisDiscountPercent);
            string  stockString         = "";

            if (thisStockItem.StockCount == 0)
            {
                stockString = "sold out";
            }
            else
            {
                stockString = $"{thisStockItem.StockCount} in stock";
            }
            string saleString = "";

            if (thisDiscountPercent != 0)
            {
                saleString = $"{thisDiscountPercent}% Off!";
            }
            else
            {
                saleString = "-";
            }
            string priceString = "";

            if (thisDiscountPercent != 0)
            {
                priceString = $"${thisPrice} each (after discount)";
            }
            else
            {
                priceString = $"${thisPrice} each";
            }
            StockItemViewModel thisStockItemViewModel = new StockItemViewModel(
                thisLocation.LocationId,
                thisProduct.ProductId,
                thisProduct.Name,
                stockString,
                false,
                saleString,
                priceString,
                thisPrice,
                thisLocation.LocationAddress,
                thisProduct.Description);

            return(thisStockItemViewModel);
        }
예제 #10
0
        // PUT: api/Employee/5
        public StockItemViewModel Put(long id, [FromBody] StockItemViewModel value)
        {
            var employee = repository.GetByID(value.Id);

            employee.Update(
                value.Name,
                value.Quantity,
                value.SellingPrice,
                value.CostPrice
                );
            repository.Update(employee);
            return(Mapper.Map <StockItemViewModel>(employee));
        }
        public async Task <IActionResult> UpdateStockItem(StockItemViewModel stockItem)
        {
            try
            {
                await _stockItemService.UpdateStockItem(stockItem);

                return(SendOkResponse());
            }
            catch (Exception ex)
            {
                return(SendErrorResponse(ex.Message));
            }
        }
예제 #12
0
        private StockItemViewModel StockItemToViewModel(StockItem item)
        {
            string             name = ShopGlobals.LocalProductRange.Products.Where(p => p.Id == item.ProductId).FirstOrDefault().Name;
            StockItemViewModel vm   = new StockItemViewModel()
            {
                Amount         = item.Amount,
                StartingAmount = item.Amount,
                Id             = item.Id,
                ProductId      = item.ProductId,
                ProductName    = name,
                Unit           = item.Unit
            };

            return(vm);
        }
예제 #13
0
        // GET: StockItems/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StockItem  stockItem = db.StockItems.Find(id);
            salesStats stats     = new salesStats(id, db);

            if (stockItem == null)
            {
                return(HttpNotFound());
            }
            StockItemViewModel viewModel = new StockItemViewModel(stockItem, stats);

            return(View(viewModel));
        }
예제 #14
0
        public async Task <IActionResult> ProductSelect(string locid = "", string prodid = "", string ovarload = "false")
        {
            /// <summary>
            /// The specific product selection page
            /// </summary>
            if (!UtilMethods.LogInCheck(_cache))
            {
                return(Redirect("/Login"));
            }
            if (locid == "")
            {
                return(Redirect("/Locations"));
            }
            int thisLocId = int.Parse(locid);

            if (prodid == "")
            {
                return(Redirect($"/LocationDetails/{thisLocId}"));
            }
            int thisProdId   = int.Parse(prodid);
            var thisLocation = await _context.Locations
                               .FirstOrDefaultAsync(m => m.LocationId == thisLocId);

            var thisProduct = await _context.Products
                              .FirstOrDefaultAsync(m => m.ProductId == thisProdId);

            var thisStockItem = await _context.StockItems
                                .FirstOrDefaultAsync(m => m.LocationId == thisLocId && m.ProductId == thisProdId);

            if (thisLocation == null || thisProduct == null || thisStockItem == null)
            {
                return(NotFound());
            }
            if (ovarload == "true")
            {
                ViewData["warn"] = "toomuch";
            }
            StockItemViewModel thisStockItemViewModel = UtilMethods.BuildStockItemViewModelFromLocStock(thisLocation, thisStockItem, _context);

            _cache.Set("currentViewedStock", thisStockItemViewModel);
            ViewData["cartcount"] = UtilMethods.GetCartCount(_cache);
            return(View(thisStockItemViewModel));
        }
예제 #15
0
        private void GetStockItems(Stock stock)
        {
            var items = DbManager.GetInstance().GetStockItemsInStock(stock.Id);

            if (StockItems != null)
            {
                StockItems.Clear();
                dgStockItems.Items.Refresh();
            }
            else
            {
                _StockItems = new ObservableCollection <StockItemViewModel>();
            }
            StockItems.CollectionChanged += StockItems_CollectionChanged;
            foreach (var item in items)
            {
                StockItemViewModel stockVm = StockItemToViewModel(item);
                StockItems.Add(stockVm);
            }
            dgStockItems.ItemsSource = StockItems;
        }
예제 #16
0
        public async Task <IActionResult> LocationDetails(int?id)
        {
            /// <summary>
            /// The store stocks page
            /// </summary>
            if (id == null)
            {
                return(NotFound());
            }
            int thisLocId = (int)id;

            if (!UtilMethods.LogInCheck(_cache))
            {
                return(Redirect("/Login"));
            }
            var thisLocation = await _context.Locations
                               .FirstOrDefaultAsync(m => m.LocationId == thisLocId);

            if (thisLocation == null)
            {
                return(NotFound());
            }
            var foundStockItems = from thisTableItem in _context.StockItems
                                  where thisTableItem.LocationId == thisLocation.LocationId
                                  select thisTableItem;
            List <StockItem>          theseStockItems          = foundStockItems.ToList <StockItem>();
            List <StockItemViewModel> theseStockItemViewModels = new List <StockItemViewModel>();

            foreach (StockItem thisStockItem in theseStockItems)
            {
                StockItemViewModel thisStockItemViewModel = UtilMethods.BuildStockItemViewModelFromLocStock(thisLocation, thisStockItem, _context);
                theseStockItemViewModels.Add(thisStockItemViewModel);
            }
            ViewData["cartcount"] = UtilMethods.GetCartCount(_cache);
            return(View(theseStockItemViewModels));
        }
예제 #17
0
 public async Task UpdateStockItem(StockItemViewModel stockItemViewModel)
 {
     StockItem stockItem = _mapper.Map <StockItem>(stockItemViewModel);
     await _stockItemDomain.UpdateStockItem(stockItem);
 }