コード例 #1
0
 public ActionResult VerifyUser(User user)
 {
     if (ModelState.IsValid)
     {
         using (ECommerceEntitiesNew Ece = new ECommerceEntitiesNew())
         {
             var userDetails = Ece.Users.Where(x => x.Name == user.Name && x.Password == user.Password).FirstOrDefault();
             if (userDetails == null)
             {
                 Console.Write("failed");
                 return(View("Index"));
             }
             else
             {
                 if (user.Name == "Admin")
                 {
                     Session["userID"]   = userDetails.Id;
                     Session["userName"] = userDetails.Name;
                     return(RedirectToAction("Index", "Admin"));
                 }
                 else
                 {
                     Session["userID"]   = userDetails.Id;
                     Session["userName"] = userDetails.Name;
                     return(RedirectToAction("Index", "Customer"));
                 }
             }
         }
     }
     ModelState.Clear();
     return(RedirectToAction("Index", "Home"));
 }
コード例 #2
0
 public ActionResult Add(User user)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (ECommerceEntitiesNew Ece = new ECommerceEntitiesNew())
             {
                 var userDetails = Ece.Users.Where(x => x.Name == user.Name).FirstOrDefault();
                 if (userDetails != null)
                 {
                     Console.Write("Username already Exists");
                     return(View("Register"));
                 }
                 else
                 {
                     var newUser = Ece.Users.Create();
                     newUser.Name     = user.Name;
                     newUser.Password = user.Password;
                     newUser.RoleId   = 2;
                     Ece.Users.Add(newUser);
                     Ece.SaveChanges();
                     return(RedirectToAction("Index", "Home"));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
     }
     ModelState.Clear();
     return(RedirectToAction("Index", "Home"));
 }
コード例 #3
0
        public object GetCart(ECommerceEntitiesNew ece)
        {
            int GrandTotal = 0;

            try
            {
                var myList = ((from temp in ece.Carts
                               select new
                {
                    Id = temp.Id,
                    Uid = temp.UId,
                    UserName = temp.User.Name,
                    Pid = temp.PId,
                    Price = temp.Product.Price,
                    ProductName = temp.Product.Name,
                    Quantity = temp.Quantity,
                    Status = temp.Status,
                    Total = temp.Quantity * temp.Product.Price
                }).OrderBy(temp => temp.Id)).Take(100).ToList();
                myList.RemoveAll(x => x.UserName != Session["userName"].ToString());
                foreach (var item in myList)
                {
                    GrandTotal = (int)(GrandTotal + item.Total);
                }
                ViewBag.GrandTot = GrandTotal;
                Session["Total"] = GrandTotal;
                var temp2 = Session["Total"];
                return(myList);
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                throw new NotImplementedException();
            }
        }
コード例 #4
0
        public int Temp()
        {
            ECommerceEntitiesNew ece = new ECommerceEntitiesNew();
            int GrandTotal           = 0;
            var myList = ((from temp in ece.Carts
                           select new
            {
                Id = temp.Id,
                Uid = temp.UId,
                UserName = temp.User.Name,
                Pid = temp.PId,
                Price = temp.Product.Price,
                ProductName = temp.Product.Name,
                Quantity = temp.Quantity,
                Status = temp.Status,
                Total = temp.Quantity * temp.Product.Price
            }).OrderBy(temp => temp.Id)).Take(100).ToList();

            myList.RemoveAll(x => x.UserName != Session["userName"].ToString());
            foreach (var item in myList)
            {
                GrandTotal = (int)(GrandTotal + item.Total);
            }
            ViewBag.GrandTot = GrandTotal;
            Session["Total"] = GrandTotal;
            var temp2 = Session["Total"];

            return(GrandTotal);
        }
コード例 #5
0
 public ActionResult Add(Product product, string cid)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (ECommerceEntitiesNew Ece = new ECommerceEntitiesNew())
             {
                 var productDetails = Ece.Users.Where(x => x.Name == product.Name).FirstOrDefault();
                 if (productDetails != null)
                 {
                     Console.Write("Product already Exists");
                     return(View("New"));
                 }
                 else
                 {
                     var newProduct = Ece.Products.Create();
                     newProduct.Name         = product.Name;
                     newProduct.Price        = product.Price;
                     newProduct.Category     = cid;
                     newProduct.Discontinued = false;
                     Ece.Products.Add(newProduct);
                     Ece.SaveChanges();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
     }
     return(RedirectToAction("Inventory", "Admin"));
 }
コード例 #6
0
 public JsonResult ConvertCart()
 {
     try
     {
         using (ECommerceEntitiesNew Ece = new ECommerceEntitiesNew())
         {
             var myList = GetCart(Ece);
             return(Json(myList, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #7
0
        //DELETE /api/customers/1
        public ActionResult DeleteProduct(int id)
        {
            ECommerceEntitiesNew Ece = new ECommerceEntitiesNew();
            var ProductInDb          = Ece.Products.SingleOrDefault(p => p.Id == id);

            Console.Write("Inside delete function");
            if (ProductInDb == null)
            {
                Console.Write("Product not found");
            }
            //Ece.Products.Remove(ProductInDb);
            ProductInDb.Discontinued = true;
            Ece.SaveChanges();
            return(View("Inventory"));
        }
コード例 #8
0
        public ActionResult PlaceOrder()
        {
            ECommerceEntitiesNew Ece = new ECommerceEntitiesNew();
            var CartElements         = Ece.Carts;

            foreach (var Element in CartElements)
            {
                if (Element.UId == Convert.ToInt32(Session["userID"]))
                {
                    var newOrder = Ece.Orders.Create();
                    newOrder.UserId    = Element.UId;
                    newOrder.ProductId = Element.PId;
                    newOrder.Quantity  = Element.Quantity.ToString();
                    Ece.Orders.Add(newOrder);
                    Ece.Carts.Remove(Element);
                }
            }
            Ece.SaveChanges();
            Session["Total"] = 0;
            return(View("Cart"));
        }
コード例 #9
0
 public object GetOrders(ECommerceEntitiesNew ece)
 {
     try
     {
         var myList = ((from temp in ece.Orders
                        select new
         {
             Id = temp.Id,
             UserName = temp.User.Name,
             ProductName = temp.Product.Name,
             Quantity = temp.Quantity
         }).OrderBy(temp => temp.Id)).Take(100).ToList();
         //myList.RemoveAll(x => x.Discontinued == true);
         return(myList);
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
         throw new NotImplementedException();
     }
 }
コード例 #10
0
 public object GetData(ECommerceEntitiesNew ece)
 {
     try
     {
         var myList = ((from temp in ece.Products
                        select new
         {
             Id = temp.Id,
             Name = temp.Name,
             Price = temp.Price,
             Category = temp.Category,
             Discontinued = temp.Discontinued
         }).OrderBy(temp => temp.Id)).Take(100).ToList();
         myList.RemoveAll(x => x.Discontinued == true);
         return(myList);
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
         throw new NotImplementedException();
     }
 }
コード例 #11
0
        public ActionResult AddToCart(int id)
        {
            int UserId    = Convert.ToInt32(Session["userID"]);
            int count     = 0;
            int quantity  = 0;
            int ProductId = 0;
            int temp      = id;

            while (temp != 0)
            {
                // n = n/10
                temp /= 10;
                ++count;
            }
            if (count == 5)
            {
                ProductId = id / 10;
                quantity  = id % 10;
            }
            else if (count == 6)
            {
                ProductId = id / 100;
                quantity  = id % 100;
            }
            else
            {
                ProductId = id / 1000;
                quantity  = id % 1000;
            }
            //////////////////////////////////////////////////////////////////////
            try
            {
                if (ModelState.IsValid)
                {
                    using (ECommerceEntitiesNew Ece = new ECommerceEntitiesNew())
                    {
                        var CartDetails = Ece.Carts.Where(x => x.UId == UserId).FirstOrDefault();
                        if (CartDetails != null)
                        {
                            var ProductInDb = Ece.Carts.SingleOrDefault(p => p.PId == ProductId);
                            if (ProductInDb != null && CartDetails.PId == ProductId)
                            {
                                ProductInDb.Quantity = ProductInDb.Quantity + quantity;
                                Ece.SaveChanges();
                                return(View("Shop"));
                            }
                            else
                            {
                                var newCart = Ece.Carts.Create();
                                newCart.UId      = UserId;
                                newCart.PId      = ProductId;
                                newCart.Quantity = quantity;
                                newCart.Status   = false;
                                Ece.Carts.Add(newCart);
                                Ece.SaveChanges();
                            }
                        }
                        else
                        {
                            var newCart = Ece.Carts.Create();
                            newCart.UId      = UserId;
                            newCart.PId      = ProductId;
                            newCart.Quantity = quantity;
                            newCart.Status   = false;
                            Ece.Carts.Add(newCart);
                            Ece.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            return(View("Shop"));
            ///////////////////////////////////////////
        }