//POst
        //[HttpPost, ActionName("Delete")]
        //[ValidateAntiForgeryToken]
        public ActionResult Delete(int id)
        {
            Content content = db.Contents.Find(id);

            db.Contents.Remove(content);
            db.SaveChanges();
            return(RedirectToAction("Display"));
        }
Example #2
0
        //public int UploadImageInDataBase(HttpPostedFileBase file, ContentViewModel contentViewModel)
        //{
        //    contentViewModel.Image = ConvertToBytes(file);
        //    var Content = new Content
        //    {
        //        Name = contentViewModel.Name,
        //        BrandId=contentViewModel.BrandId,
        //        CategoryId=contentViewModel.CategoryId,
        //        price = contentViewModel.price,
        //        Review = contentViewModel.Review,
        //        Description = contentViewModel.Description,
        //        Image = contentViewModel.Image


        //    };
        //    db.Contents.Add(Content);

        //    int i = db.SaveChanges();
        //    if (i == 1)
        //    {
        //        return 1;
        //    }
        //    else
        //    {
        //        return 0;
        //    }
        public int AddUpdateUserData(UserDataViewModel userdataviewmodel)
        {
            if (userdataviewmodel.UserId == 0)
            {
                var UserData = new User
                {
                    FirstName = userdataviewmodel.FirstName,
                    LastName  = userdataviewmodel.LastName,
                    Gender    = userdataviewmodel.Gender,
                    Email     = userdataviewmodel.Email,
                    Password  = userdataviewmodel.Password,
                    PhoneNo   = userdataviewmodel.PhoneNo,
                    Address   = userdataviewmodel.Address,
                    BirthDate = userdataviewmodel.BirthDate
                };
                db.Users.Add(UserData);
            }
            else
            {
                User updateData = (from a in db.Users
                                   where a.UserId == userdataviewmodel.UserId
                                   select a).FirstOrDefault();
                updateData.FirstName = userdataviewmodel.FirstName;
                updateData.LastName  = userdataviewmodel.LastName;
                updateData.Gender    = userdataviewmodel.Gender;
                updateData.Email     = userdataviewmodel.Email;
                updateData.Password  = userdataviewmodel.Password;
                updateData.PhoneNo   = userdataviewmodel.PhoneNo;
                updateData.Address   = userdataviewmodel.Address;
                updateData.BirthDate = userdataviewmodel.BirthDate;
            }
            int i = db.SaveChanges();

            if (i == 1)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
 public ActionResult AddUser(User model)
 {
     using (ShoppingCartAppEntities entities = new ShoppingCartAppEntities())
     {
         entities.Users.Add(model);
         entities.SaveChanges();
         int UserId = model.UserId;
         //return RedirectToAction("Display");
         ViewBag.result = " Registration Successful!";
     }
     SendActivationEmail(model);
     return(View(model));
 }
        public ActionResult EditYourProfile(UserDataViewModel obj)
        {
            using (ShoppingCartAppEntities db = new ShoppingCartAppEntities())
            {
                ContentRepository service = new ContentRepository();

                int i = service.AddUpdateUserData(obj); if (i == 1)
                {
                    return(RedirectToAction("UserProfile"));
                }
                db.SaveChanges();
                return(RedirectToAction("UserProfile"));
            }
        }
        public ActionResult Edit(ContentViewModel obj)
        {
            try
            {
                using (ShoppingCartAppEntities db = new ShoppingCartAppEntities())
                {
                    HttpPostedFileBase file    = Request.Files["ImageData"];
                    ContentRepository  service = new ContentRepository();

                    int i = service.AddUpdateConttentData(file, obj); if (i == 1)
                    {
                        return(RedirectToAction("Display"));
                    }
                    db.SaveChanges();
                    return(RedirectToAction("Display"));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Login"));
            }
        }
        public ActionResult AddQuantity(int ProductId, int UserId)
        {
            ShoppingCartAppEntities db = new ShoppingCartAppEntities();
            int           Quantity;
            CartViewModel cm = new CartViewModel();

            var data = (from a in db.UserCarts
                        where a.UserId == UserId && a.ProductId == ProductId
                        select a.ProductId).Count();
            var data_user = db.UserCarts.Count(a => a.UserId == UserId);

            if (data_user == 0)
            {
                Quantity = 1;
                UserCart c = new UserCart()
                {
                    UserId    = UserId,
                    ProductId = ProductId,
                    DateTime  = System.DateTime.Now,
                    Quantity  = Quantity,
                };

                db.UserCarts.Add(c);
                db.SaveChanges();
            }
            else
            {
                if (data == 0)
                {
                    Quantity = 1;
                    UserCart c = new UserCart()
                    {
                        UserId    = UserId,
                        ProductId = ProductId,
                        DateTime  = System.DateTime.Now,
                        Quantity  = Quantity,
                    };

                    db.UserCarts.Add(c);
                    db.SaveChanges();
                }
                else
                {
                    var abc = (from a in db.UserCarts
                               where a.ProductId == (ProductId) && a.UserId == (UserId)
                               select a.Quantity).Single();

                    int QuantityData = System.Convert.ToInt32(abc);
                    QuantityData++;

                    var result = db.UserCarts.SingleOrDefault(b => b.ProductId == ProductId && b.UserId == UserId);
                    result.ProductId = ProductId;
                    result.Quantity  = QuantityData;
                    result.UserId    = UserId;
                    result.DateTime  = System.DateTime.Now;

                    db.SaveChanges();
                }
            }


            var count = (from a in db.UserCarts
                         where a.UserId == (UserId)
                         select a.Quantity).Sum();

            ViewBag.cartCount = count;


            return(Redirect("MyorderPartial"));
        }
        public ActionResult Add(int ProductId, int UserId)
        {
            ShoppingCartAppEntities db = new ShoppingCartAppEntities();
            int           Quantity;
            CartViewModel cm = new CartViewModel();
            // var roductId = db.UserCarts.AsNoTracking().Where(p => p.ProductId == ProductId).FirstOrDefault();
            // var roductId = db.UserCarts.Find(ProductId);
            //   var roductId = from u in db.UserCarts.Where(p => p.ProductId == ProductId).Select(v => v.ProductId) select ProductId;
            // var data = db.UserCarts.Count(a => a.ProductId == ProductId);
            var data = (from a in db.UserCarts
                        where a.UserId == UserId && a.ProductId == ProductId
                        select a.ProductId).Count();
            var data_user = db.UserCarts.Count(a => a.UserId == UserId);

            if (data_user == 0)
            {
                Quantity = 1;
                UserCart c = new UserCart()
                {
                    UserId    = UserId,
                    ProductId = ProductId,
                    DateTime  = System.DateTime.Now,
                    Quantity  = Quantity,
                };

                db.UserCarts.Add(c);
                db.SaveChanges();
            }
            else
            {
                if (data == 0)
                {
                    Quantity = 1;
                    UserCart c = new UserCart()
                    {
                        UserId    = UserId,
                        ProductId = ProductId,
                        DateTime  = System.DateTime.Now,
                        Quantity  = Quantity,
                    };

                    db.UserCarts.Add(c);
                    db.SaveChanges();
                }
                else
                {
                    var abc = (from a in db.UserCarts
                               where a.ProductId == (ProductId) && a.UserId == (UserId)
                               select a.Quantity).Single();

                    int pqr = System.Convert.ToInt32(abc);
                    pqr++;

                    var result = db.UserCarts.SingleOrDefault(b => b.ProductId == ProductId && b.UserId == UserId);
                    result.ProductId = ProductId;
                    result.Quantity  = pqr;
                    result.UserId    = UserId;
                    result.DateTime  = System.DateTime.Now;

                    db.SaveChanges();
                }
            }


            var count = (from a in db.UserCarts
                         where a.UserId == (UserId)
                         select a.Quantity).Sum();

            ViewBag.cartCount = count;


            //  TempData["ProductAddedToCart"] = "Product added to cart successfully";
            //  return RedirectToAction("Display", ViewBag.cartCount);
            return(RedirectToAction("DisplayPartial", ViewBag.cartCount));
        }