Beispiel #1
0
        public ActionResult SaveProdcut(Product prod)
        {
            try
            {
                HttpPostedFileBase postedFile = Request.Files["file"];
                postedFile.SaveAs(Server.MapPath("~/Content/image/") + System.IO.Path.GetFileName(postedFile.FileName));

                if (postedFile.FileName != "" && prod.Name != null &&
                    prod.Price > 0 && prod.Quantity > 0)
                {
                    prod.Image = "image/" + postedFile.FileName;
                    context.Products.Add(prod);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var category = (from cat in context.Categories
                                    select cat).ToList();
                    ViewBag.cat = category;
                    return(View("AddProduct", prod));
                }
            }
            catch
            {
                var category = (from cat in context.Categories
                                select cat).ToList();
                ViewBag.cat = category;
                return(View("AddProduct", prod));
            }
        }
        public ActionResult Create(Category cate)
        {
            try
            {
                HttpPostedFileBase postedFile = Request.Files["file"];
                postedFile.SaveAs(Server.MapPath("~/Content/image/") + System.IO.Path.GetFileName(postedFile.FileName));
                cate.Image = "image/" + postedFile.FileName;
                context.Categories.Add(cate);
                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(cate));
            }
        }
 public int InsertCategory(Category model)
 {
     using (var context = new OnlineShopingEntities())
     {
         Category category = new Category()
         {
             CategoryName = model.CategoryName
         };
         context.Categories.Add(category);
         context.SaveChanges();
         return(category.CategoryId);
     }
 }
        public int Operation(RegistrationModel model)
        {
            using (var context = new OnlineShopingEntities())
            {
                User user = new User()
                {
                    UserName = model.UserName,

                    Password = HashFunction(model.Password)
                };
                context.Users.Add(user);
                context.SaveChanges();
                return(user.UserId);
            }
        }
 public int InsertProduct(ProductModel model)
 {
     using (var context = new OnlineShopingEntities())
     {
         Product product = new Product()
         {
             ProductName = model.ProductName,
             Price       = model.Price,
             ProductDate = DateTime.Today,
             Quantity    = model.Quantity,
             CategoryId  = model.CategoryId
         };
         context.Products.Add(product);
         context.SaveChanges();
         return(product.ProductId);
     }
 }
 public int InsertUserInfo(UserInformation model, string UserName)
 {
     using (var context = new OnlineShopingEntities())
     {
         var             user            = context.Users.Where(x => x.UserName == UserName).FirstOrDefault();
         UserInformation userInformation = new UserInformation()
         {
             Name        = model.Name,
             Address     = model.Address,
             PhoneNumber = model.PhoneNumber,
             Email       = model.Email,
             UserId      = user.UserId
         };
         context.UserInformations.Add(userInformation);
         context.SaveChanges();
         return(userInformation.UserInfoId);
     }
 }
Beispiel #7
0
        public int UpdateProduct(ProductPriceUpdateModel model)
        {
            using (var context = new OnlineShopingEntities())
            {
                var product = context.Products.Where(x => x.ProductId == model.ProductId).FirstOrDefault();
                if (product != null)
                {
                    product.Price = model.price;
                }
                else
                {
                    return(-1);
                }

                context.SaveChanges();
                return(product.ProductId);
            }
        }
Beispiel #8
0
        public ActionResult AddOrders(int ID)
        {
            Order OR    = new Order();
            var   check = (from o in  context.Orders
                           where o.ProductID == ID select o).FirstOrDefault();
            Product pro = context.Products.FirstOrDefault(p => p.ID == ID);

            if (check == null)
            {
                if (pro.Quantity > 0)
                {
                    pro.Quantity = pro.Quantity - 1;
                    OR.ProductID = ID;
                    OR.Quantity  = 1;
                    context.Orders.Add(OR);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                if (pro.Quantity > 0)
                {
                    check.Quantity = check.Quantity + 1;
                    pro.Quantity   = pro.Quantity - 1;
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }



            /*  if (check.ID!=null && check.ID > 0)
             * {
             *    if (pro.Quantity > 0) {
             *        check.Quantity += 1;
             *        pro.Quantity = pro.Quantity - 1;
             *        context.SaveChanges();
             *        return RedirectToAction("Index");
             *    }
             * else { return RedirectToAction("Index"); }
             * }
             * else
             * {
             *    if (pro.Quantity > 0)
             *    {
             *        pro.Quantity = pro.Quantity - 1;
             *        OR.ProductID = ID;
             *        OR.Quantity= 1;
             *        context.Orders.Add(OR);
             *        context.SaveChanges();
             *        return RedirectToAction("Index");
             *    }
             *    else { return RedirectToAction("Index"); }
             * }*/
        }