Ejemplo n.º 1
0
        public ActionResult CheckOut()
        {
            List <shoppingcart> shoppingcartitems = new List <shoppingcart>();
            product             product           = new product();
            EmailService        mail    = new EmailService();
            IdentityMessage     message = new IdentityMessage();
            var keys = Request.Form.AllKeys;

            message.Destination = Request.Form.Get(keys[0]);
            message.Subject     = "Order confirmation Bright Yellow";
            message.Body        = "Thank you for your purchase. <br />You purchased the following items:";
            using (new_testEntities db = new new_testEntities())
            {
                string userid = "0";
                if (Request.IsAuthenticated)
                {
                    userid = User.Identity.GetUserId();
                }
                shoppingcartitems = db.shoppingcart.Where(x => x.UserId == userid).ToList();

                foreach (shoppingcart item in shoppingcartitems)
                {
                    product       = db.product.FirstOrDefault(x => x.ID == item.ProductId);
                    product.stock = product.stock - item.Quantity;
                    message.Body  = message.Body + "<br />" + product.ProductName;
                    if (product.PurchasedQuantity == null)
                    {
                        product.PurchasedQuantity = 1;
                    }
                    product.PurchasedQuantity = product.PurchasedQuantity + item.Quantity;
                    db.SaveChanges();
                    db.shoppingcart.Remove(item);
                    db.SaveChanges();
                    int             productid   = item.ProductId;
                    int             quantity    = (int)item.Quantity;
                    DateTime        date        = DateTime.Now;
                    string          productname = product.ProductName;
                    string          imagePath   = product.imagepath;
                    purchasehistory ph          = new purchasehistory
                    {
                        ProductID    = productid,
                        UserID       = userid,
                        Quantity     = quantity,
                        PurchaseDate = date,
                        ProductName  = productname,
                        imagepath    = imagePath
                    };
                    db.purchasehistory.Add(ph);
                    db.SaveChanges();
                }
                try
                {
                    mail.SendAsync(message);
                }
                catch
                {
                }
            }
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult Minus_To_Cart(int id)
        {
            //Console.WriteLine("Add to shoppingcart is succesfully called");
            int?ProductId;

            ProductId = id;


            using (new_testEntities db = new new_testEntities())
            {
                //user user = db.user.FirstOrDefault(x => x.ID == id);
                shoppingcart Shoppingcart = db.shoppingcart.FirstOrDefault(x => x.ProductId == id);


                Shoppingcart.Quantity -= 1;
                db.SaveChanges();

                if (Shoppingcart.Quantity <= 0)
                {
                    db.shoppingcart.Remove(Shoppingcart);
                    db.SaveChanges();
                }


                return(RedirectToAction("Index", "Shoppingcart"));
            }
        }
Ejemplo n.º 3
0
        //[HttpGet]
        public ActionResult Add_To_Wishlist(int id)
        {
            //Console.WriteLine("Add to wishlist is succesfully called");
            ID = id;


            using (new_testEntities db = new new_testEntities())
            {
                //user user = db.user.FirstOrDefault(x => x.ID == id);
                product  product  = db.product.FirstOrDefault(x => x.ID == id);
                string   userid   = User.Identity.GetUserId();
                wishlist Wishlist = db.wishlist.FirstOrDefault(x => x.ProductId == id && x.UserId == userid);

                if (Wishlist == null)
                {
                    db.wishlist.Add(new wishlist {
                        ProductId = product.ID, UserId = userid, Quantity = 1, ProductName = product.ProductName, Price = product.price, Imagepath = product.imagepath
                    });
                    db.SaveChanges();
                }
                else
                {
                    Wishlist.Quantity += 1;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Wishlist"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Minus_To_Wishlist(int id)
        {
            //Console.WriteLine("Add to wishlist is succesfully called");
            int?ProductId;

            ProductId = id;


            using (new_testEntities db = new new_testEntities())
            {
                //user user = db.user.FirstOrDefault(x => x.ID == id);
                wishlist Wishlist = db.wishlist.FirstOrDefault(x => x.ProductId == id);


                Wishlist.Quantity -= 1;
                db.SaveChanges();

                if (Wishlist.Quantity <= 0)
                {
                    db.wishlist.Remove(Wishlist);
                    db.SaveChanges();
                }


                return(RedirectToAction("Index", "Wishlist"));
            }
        }
Ejemplo n.º 5
0
        public ActionResult Add_To_Cart(int id)
        {
            //Console.WriteLine("Add to wishlist is succesfully called");
            int?ProductId;

            ProductId = id;


            using (new_testEntities db = new new_testEntities())
            {
                product product = db.product.FirstOrDefault(x => x.ID == id);
                string  userid  = "0";
                if (Request.IsAuthenticated)
                {
                    userid = User.Identity.GetUserId();
                }
                shoppingcart shoppingcart = db.shoppingcart.FirstOrDefault(x => x.ProductId == id && x.UserId == userid);
                wishlist     Wishlist     = db.wishlist.FirstOrDefault(x => x.ProductId == id);

                if (shoppingcart == null)
                {
                    db.shoppingcart.Add(new shoppingcart {
                        ProductId = Wishlist.ProductId, UserId = User.Identity.GetUserId(), Quantity = Wishlist.Quantity, ProductName = Wishlist.ProductName, Price = Wishlist.Price, Imagepath = Wishlist.Imagepath
                    });
                    db.SaveChanges();
                }
                else
                {
                    shoppingcart.Quantity += Wishlist.Quantity;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Shoppingcart"));
            }
        }
Ejemplo n.º 6
0
        public ActionResult Delete(int id)
        {
            using (new_testEntities db = new new_testEntities())
            {
                shoppingcart shoppingcart = db.shoppingcart.FirstOrDefault(x => x.ProductId == id);
                db.shoppingcart.Remove(shoppingcart);
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Shoppingcart"));
        }
Ejemplo n.º 7
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         using (ApplicationDbContext db2 = new ApplicationDbContext())
         {
             if (User.IsInRole("Admin"))
             {
                 // TODO: Add insert logic here
                 using (new_testEntities db = new new_testEntities())
                 {
                     product p = new product
                     {
                         price       = Convert.ToDecimal(collection[11]),
                         imagepath   = collection[9],
                         stock       = 100,
                         Brand       = collection[1],
                         Supplier    = "testsupplier",
                         ProductName = collection[10]
                     };
                     ram r = new ram
                     {
                         ID    = p.ID,
                         Brand = p.Brand,
                         CompositionOfMemory    = collection[2],
                         MemoryType             = collection[3],
                         Clockspeed             = Convert.ToInt32(collection[4]),
                         CASlatency             = Convert.ToInt32(collection[5]),
                         Voltage                = (float)Convert.ToDouble(collection[6]),
                         MemoryModuleConnection = Convert.ToInt32(collection[7]),
                         MemorySuitableFor      = collection[8],
                         ImagePath              = p.imagepath,
                         Name    = p.ProductName,
                         Price   = p.price,
                         Ramsize = Convert.ToInt32(collection[12])
                     };
                     db.product.Add(p);
                     db.ram.Add(r);
                     db.SaveChanges();
                 }
             }
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 8
0
 // GET: Statistics/Delete/5
 public ActionResult Delete(int id)
 {
     using (ApplicationDbContext db2 = new ApplicationDbContext())
     {
         if (User.IsInRole("Admin"))
         {
             using (new_testEntities db = new new_testEntities())
             {
                 ram     ram     = db.ram.FirstOrDefault(r => r.ID == id);
                 product product = db.product.FirstOrDefault(p => p.ID == id);
                 db.ram.Remove(ram);
                 db.product.Remove(product);
                 db.SaveChanges();
             }
         }
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 9
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                using (ApplicationDbContext db2 = new ApplicationDbContext())
                {
                    if (User.IsInRole("Admin"))
                    {
                        using (new_testEntities db = new new_testEntities())
                        {
                            // TODO: Add update logic here
                            ram     ram     = db.ram.FirstOrDefault(r => r.ID == id);
                            product product = db.product.FirstOrDefault(p => p.ID == id);
                            ram.ImagePath              = collection[10];
                            product.imagepath          = collection[10];
                            ram.Brand                  = collection[2];
                            product.Brand              = collection[2];
                            ram.CompositionOfMemory    = collection[3];
                            ram.MemoryType             = collection[4];
                            ram.Clockspeed             = Convert.ToInt32(collection[5]);
                            ram.CASlatency             = Convert.ToInt32(collection[6]);
                            ram.Voltage                = (float)Convert.ToDouble(collection[7]);
                            ram.MemoryModuleConnection = Convert.ToInt32(collection[8]);
                            ram.MemorySuitableFor      = collection[9];
                            ram.Name            = collection[11];
                            product.ProductName = collection[11];
                            ram.Price           = Convert.ToDecimal(collection[12]);
                            product.price       = Convert.ToDecimal(collection[12]);
                            ram.Ramsize         = Convert.ToInt32(collection[13]);

                            db.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(View());
            }
        }