Esempio n. 1
0
        /// <summary>
        /// Delete the inventory data
        /// </summary>
        public void DeleteInventory(CupCake b, Product p)
        {
            _logger.LogInformation("Deleting product {ProductId}", p);

            _dbContext.Inventory.Remove(_dbContext.Inventory.
                                        First(i => (i.LocationId == b.LocationId) && (i.ProductId == p.ProductId)));
        }
        public ActionResult PlaceOrder(string id, CustomerModel cModel)
        {
            try
            {
                List <CupCake> location = new List <CupCake>();
                int            storeID  = int.Parse(TempData["storeID"].ToString());
                _repository.GetStores(location);
                CupCake  choice = _repository.SelectStore(location, storeID);
                Customer c      = new Customer(cModel.FirstName, cModel.LastName);
                if (!_repository.SearchForCustomer(c))
                {
                    _repository.AddNewCustomer(c);
                }
                else
                {
                    var retCust = _repository.GetCustomerByName(c.FirstName, c.LastName);
                    c.CustomerId = retCust.CustomerId;
                }
                Product p = _repository.GetProductByTitle(id, choice);
                Order   o = new Order();
                _repository.MakeOrder(c.CustomerId, choice.LocationId, o);
                p.ReduceInventory();
                _repository.EditInventory(choice, p);
                _repository.AddProductToOrder(o, p);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Edit the inventory data
        /// </summary>
        public void EditInventory(CupCake b, Product p)
        {
            _logger.LogInformation("Updating Product {ProductId}", p);

            var Inventory = _dbContext.Inventory.First(i => (i.LocationId == b.LocationId) && (i.ProductId == p.ProductId));

            Inventory.InventoryAmount = p.InventoryAmount;
            _dbContext.SaveChanges();
            p.ProductId = Inventory.ProductId;
        }
Esempio n. 4
0
        /// <summary>
        /// Get products by name
        /// </summary>
        public Product GetProductByTitle(string search, CupCake b)
        {
            var sqlProduct   = _dbContext.Products.First(p => p.Pname == search);
            var sqlInventory = _dbContext.Inventory.First(i =>
                                                          (i.ProductId == sqlProduct.ProductId) && (b.LocationId == i.LocationId));
            Product product = new Product(sqlProduct.ProductId, sqlProduct.Pname,
                                          sqlProduct.Price, sqlInventory.InventoryAmount);

            return(product);
        }
Esempio n. 5
0
        public IActionResult CreatePost(CupCake cupCake)
        {
            if (ModelState.IsValid)
            {
                _repository.CreateCupCake(cupCake);
                return(RedirectToAction(nameof(Index)));
            }
            PopulateBakeriesDropDownList(ViewBag.BakeryId);

            return(View(cupCake));
        }
Esempio n. 6
0
        /// <summary>
        /// Get all Stores with deferred execution,

        /// </summary>
        /// <returns>The collection of stores</returns>
        public List <CupCake> GetStores(List <CupCake> locations)
        {
            if (_dbContext.Stores.Any())
            {
                foreach (Stores store in _dbContext.Stores)
                {
                    CupCake b = new CupCake(store.LocationId, $"{store.City}, {store.State}");
                    locations.Add(b);
                }
            }
            else
            {
                Console.WriteLine("There are no stores open");
            }
            return(locations);
        }
Esempio n. 7
0
        public IActionResult GetImage(int id)
        {
            CupCake requestedCupcake = _repository.GetCupCakeById(id);

            if (requestedCupcake != null)
            {
                string webRootpath = _environment.WebRootPath;
                string folderPath  = "\\images\\";
                string fullPath    = webRootpath + folderPath + requestedCupcake.ImageName;
                if (System.IO.File.Exists(fullPath))
                {
                    FileStream fileOnDisk = new FileStream(fullPath, FileMode.Open);
                    byte[]     fileBytes;
                    using (BinaryReader br = new BinaryReader(fileOnDisk))
                    {
                        fileBytes = br.ReadBytes((int)fileOnDisk.Length);
                    }
                    return(File(fileBytes, requestedCupcake.ImageMimeType));
                }
                else
                {
                    if (requestedCupcake.PhotoFile.Length > 0)
                    {
                        return(File(requestedCupcake.PhotoFile, requestedCupcake.ImageMimeType));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }
            else
            {
                return(NotFound());
            }
        }