Beispiel #1
0
        public string AddNewProduct(AddProductViewModel addProduct, string userid)
        {
            try
            {
                Product newproduct = new Product()
                {
                    ProductName = addProduct.ProductName,
                    Description = addProduct.Description,
                    CategoryID  = categoryS.GetCategoryID(addProduct.Category),
                    DateCreated = DateTime.Now,
                    ExpieryDate = addProduct.ExpieryDate,
                    Supplier    = addProduct.Supplier,
                    UnitPrice   = addProduct.UnitPrice,
                    Image       = ProductServices.ImageConvertToByte(addProduct.AddImage),

                    Quantity = addProduct.Quantity,
                    UserId   = userid
                };
                dbContext.products.Add(newproduct);
                dbContext.SaveChanges();
                return("Success");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return("An Error Occurred");
            }

            //at System.Data.Entity.Internal.InternalContext.SaveChanges()
            //at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
            //at System.Data.Entity.DbContext.SaveChanges()
            //at Web_Store.Services.ProductServices.AddNewProduct(AddProductViewModel addProduct, String userid)
            //	in C: \Users\Stanley\source\repos\Web Store\Web Store\Services\ProductServices.cs:line 29
        }
Beispiel #2
0
        public List <ImagProduct> GetProducts(string category)
        {
            List <Product> products = new List <Product>();

            if (string.IsNullOrEmpty(category) || category == "All")
            {
                products = dbContext.products.ToList();
            }
            else
            {
                int cId = categoryS.GetCategoryID(category);
                products = dbContext.products.Where(o => o.CategoryID == cId)
                           .ToList();
            }
            List <ImagProduct> ImagProducts = new List <ImagProduct>();

            foreach (var item in products)
            {
                ImagProduct imagProduct = new ImagProduct()
                {
                    ProductID   = item.ProductID,
                    Description = item.Description,
                    Image       = ProductServices.ImageConvertToString(item.Image),
                    DateCreated = item.DateCreated,
                    ExpieryDate = item.ExpieryDate,
                    ProductName = item.ProductName,
                    Supplier    = item.Supplier,
                    UnitPrice   = item.UnitPrice,
                    Quantity    = item.Quantity,
                    CategoryID  = item.CategoryID
                };
                ImagProducts.Add(imagProduct);
            }

            return(ImagProducts);
        }