Beispiel #1
0
        public ActionResult SubmitData(Product p)
        {
            HttpFileCollectionWrapper wrapper = HttpContext.Request.Files as HttpFileCollectionWrapper;


            p.picture1 = GetByteArray(wrapper[0]);
            p.picture2 = GetByteArray(wrapper[1]);
            p.picture3 = GetByteArray(wrapper[2]);
            if (ModelState.IsValid)

            {
                using (var ctx = new BuyForUDB())
                {
                    User user = ctx.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
                    if (user != null)
                    {
                        p.Owner = ctx.Users.Where(u => u.Id == user.Id).FirstOrDefault();
                        ctx.Users.Attach(p.Owner);
                    }
                    p.Date = DateTime.Now;
                    ctx.Product.Add(p);
                    ctx.SaveChanges();
                    ViewBag.Message = "File uploaded successfully";
                }

                return(RedirectToAction("HomePage", "Home"));
            }
            return(View("AddProduct"));
        }
Beispiel #2
0
        public ActionResult ShowPicture3(int id)
        {
            using (var ctx = new BuyForUDB())
            {
                var imageData = ctx.Product.Where(p => p.Id == id && p.picture3 != null).FirstOrDefault();

                return(File(imageData.picture3, "image/jpg"));
            }
        }
Beispiel #3
0
        public ActionResult MoreDedails(int id)
        {
            Product Dedails;

            using (var ctx = new BuyForUDB())
            {
                Dedails = ctx.Product.Include(p => p.Owner).Where(p => p.Id == id).FirstOrDefault();
            }
            return(View(Dedails));
        }
Beispiel #4
0
        public ActionResult OrderByDate()
        {
            List <Product> list;

            using (var ctx = new BuyForUDB())
            {
                list = ctx.Product.Where(p => p.Status != State.Sold).OrderBy(p => p.Date).ToList();
                return(View("HomePage", list));
            }
        }
        public ActionResult Cart()

        {
            var ItemToCart = new List <Product>();

            using (var ctx = new BuyForUDB())
            {
                ItemToCart = ctx.Product.Where(p => p.Status == State.ShoppingCart &&
                                               p.User.UserName == User.Identity.Name).ToList();
            }
            return(View(ItemToCart));
        }
        public decimal RemoveFromCart(int id)
        {
            Product item;

            using (var ctx = new BuyForUDB())
            {
                item          = ctx.Product.Include(p => p.User).Where(p => p.Id == id).FirstOrDefault();
                item.UserId   = null;
                item.Status   = State.ForSale;
                item.IsInCart = false;
                ctx.SaveChanges();
            }
            return(item.Price);
        }
Beispiel #7
0
 public ActionResult ShowInHomePage(int id)
 {
     using (var ctx = new BuyForUDB())
     {
         var imageData = ctx.Product.Where(p => p.Id == id &&
                                           p.picture1 != null &&
                                           p.Status != State.Sold).FirstOrDefault();
         if (imageData != null)
         {
             return(File(imageData.picture1, "image/jpg"));
         }
         return(View());
     }
 }
Beispiel #8
0
 public ActionResult EditUser()
 {
     using (var ctx = new BuyForUDB())
     {
         var user = ctx.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
         if (user != null)
         {
             return(View("EditUser", user));
         }
         else
         {
             return(View("EditUser", new User()));
         }
     }
 }
Beispiel #9
0
        // GET: Home

        public ActionResult HomePage(string Massege)
        {
            if (Massege != null)
            {
                ViewBag.Massege1 = Massege;
            }
            var list = new List <Product>();

            using (var ctx = new BuyForUDB())
            {
                list = ctx.Product.Where(p => p.Status != State.Sold).ToList();

                return(View(list));
            }
        }
        public ActionResult Sale()
        {
            var ItemToSale = new List <Product>();

            using (var ctx = new BuyForUDB())
            {
                ItemToSale = ctx.Product.Where(p => p.Status == State.ShoppingCart &&
                                               p.User.UserName == User.Identity.Name).ToList();
                foreach (var item in ItemToSale)
                {
                    item.Status = State.Sold;
                }
                ctx.SaveChanges();
                ViewBag.Massege1 = "תודה על קניתך";
                return(RedirectToAction("HomePage", "Home"));
            }
        }
        public ActionResult AddToCart(int id)
        {
            Product item;

            using (var ctx = new BuyForUDB())
            {
                item = ctx.Product.Include(p => p.User).Where(p => p.Id == id).FirstOrDefault();
                User user = ctx.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
                if (user != null)
                {
                    item.User = ctx.Users.Where(u => u.Id == user.Id).FirstOrDefault();
                    ctx.Users.Attach(item.User);
                }

                item.Status   = State.ShoppingCart;
                item.IsInCart = true;
                ctx.SaveChanges();
            }
            return(RedirectToAction("HomePage", "Home"));
        }
Beispiel #12
0
        public ActionResult Login(User user)
        {
            if (user.UserName == null || user.Password == null)
            {
                string str = "שדות שם משתמש וסיסמא הינם שדות חובה!!!";
                return(RedirectToAction("HomePage", "Home", new { Massege = str, user = user }));
                //return View();
                //return RedirectToAction("HomePage", "Home");
            }
            else
            {
                using (var ctx = new BuyForUDB())
                {
                    var userDtails = ctx.Users.Where
                                         (u => u.UserName == user.UserName &&
                                         u.Password == user.Password)
                                     .FirstOrDefault();

                    if (userDtails != null)

                    {
                        //FormsAuthentication.SetAuthCookie($"{userDtails.FirstName} {userDtails.LastNama}", true);
                        FormsAuthentication.SetAuthCookie($"{userDtails.UserName}", true);


                        return(RedirectToAction("HomePage", "Home"));
                    }

                    else
                    {
                        string str = "שם המשתמש או הסיסמא לא נכונים !!!";
                        return(RedirectToAction("HomePage", "Home", new { Massege = str }));
                        // return View("Login");
                    }
                }
            }
        }
Beispiel #13
0
 public ViewResult EditUser(User u)
 {
     if (ModelState.IsValid)
     {
         using (var ctx = new BuyForUDB())
         {
             var ExistsUser = ctx.Users.Where(User => User.UserName == u.UserName).FirstOrDefault();
             if (!User.Identity.IsAuthenticated)
             {
                 if (ExistsUser == null)
                 {
                     ctx.Users.Add(u);
                     ctx.SaveChanges();
                     ViewBag.Massege = "פרטי משתמש נקלטו בהצלחה";
                     // return RedirectToAction("HomePage", "Home");
                     return(View("EditUser"));
                 }
                 else
                 {
                     ViewBag.Massege = "שם משתמש כבר קיים !!!";
                     return(View("EditUser"));
                 }
             }
             else
             {
                 ExistsUser.ConfirmPassword = u.ConfirmPassword;
                 ctx.Users.AddOrUpdate(u);
                 ctx.SaveChanges();
                 ViewBag.Massege = "העדכון הצליח";
                 return(View("EditUser"));
                 // return RedirectToAction("HomePage", "Home");
             }
         }
     }
     return(View("EditUser", new User()));
 }