Beispiel #1
0
 public ActionResult NewProfile()
 {
     if (Request.Cookies["SignInCookie"] != null)
     {
         string[]   cookie     = Request.Cookies["SignInCookie"].Value.Split(',');
         int        userId     = int.Parse(cookie[0]);
         User       user       = UsersRepository.GetUser(userId);
         SignInUser signInUser = new SignInUser()
         {
             FirstName            = user.FirstName,
             LastName             = user.LastName,
             BirthDate            = user.BirthDate,
             Email                = user.Email,
             UserName             = user.UserName,
             Password             = user.Password,
             VerificationPassword = user.Password
         };
         LoginSignModel loginSignModel = new LoginSignModel()
         {
             SignInUser = signInUser
         };
         return(View(loginSignModel));
     }
     return(RedirectToAction("SignIn"));
 }
Beispiel #2
0
        public ActionResult Sell(LoginSignModel loginSignModel, HttpPostedFileBase picture1, HttpPostedFileBase picture2, HttpPostedFileBase picture3)
        {
            ViewBag.IsSold = false;
            if (ModelState.IsValid)
            {
                string[] cookie       = Request.Cookies["SignInCookie"].Value.Split(',');
                int      userId       = int.Parse(cookie[0]);
                Product  productToAdd = new Product()
                {
                    OwnerId          = userId,
                    Title            = loginSignModel.SellingProduct.Title,
                    ShortDescription = loginSignModel.SellingProduct.ShortDescription,
                    LongDescription  = loginSignModel.SellingProduct.LongDescription,
                    Date             = loginSignModel.SellingProduct.Date,
                    Price            = loginSignModel.SellingProduct.Price,
                    Picture1         = ConvertToByteArry(picture1),
                    Picture2         = ConvertToByteArry(picture2),
                    Picture3         = ConvertToByteArry(picture3),
                    State            = 1
                };

                ProductsRepository.Sell(productToAdd);
                ViewBag.IsSold = true;
            }

            return(View());
        }
Beispiel #3
0
        public ActionResult SignIn(LoginSignModel loginSignModel)
        {
            User userToAdd = null;

            if (ModelState.IsValid)
            {
                UsersRepository.Add(loginSignModel.SignInUser.FirstName, loginSignModel.SignInUser.LastName, loginSignModel.SignInUser.BirthDate, loginSignModel.SignInUser.Email, loginSignModel.SignInUser.UserName, loginSignModel.SignInUser.Password, out userToAdd);
                HttpCookie cookie = new HttpCookie("SignInCookie");
                cookie.Value   = userToAdd.Id.ToString() + "," + userToAdd.FirstName;
                cookie.Expires = DateTime.Now.AddMinutes(10);
                this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
                return(RedirectToAction("Index", loginSignModel));
            }
            return(View(loginSignModel));
        }
Beispiel #4
0
        public ActionResult Cart()
        {
            LoginSignModel loginSignModel = new LoginSignModel();

            if (Request.Cookies["SignInCookie"] != null)
            {
                string[] cookie = Request.Cookies["SignInCookie"].Value.Split(',');
                int      userId = int.Parse(cookie[0]);
                loginSignModel.Products = UsersRepository.GetCart(userId);
            }
            else if (Session["cart"] != null)
            {
                List <Product> cart = (List <Product>)Session["cart"];
                loginSignModel.Products = cart;
            }
            return(View(loginSignModel));
        }
Beispiel #5
0
        // GET: Product
        public ActionResult Detail(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            var product    = ProductsRepository.GetProduct(id.Value);
            var user       = UsersRepository.GetUser(product.OwnerId);
            var signInUser = new SignInUser()
            {
                FirstName = user.FirstName, LastName = user.LastName, Email = user.Email
            };
            LoginSignModel loginSignModel = new LoginSignModel()
            {
                Product = product, SignInUser = signInUser
            };

            return(View(loginSignModel));
        }
Beispiel #6
0
 public ActionResult Index(LoginSignModel loginSignModel)
 {
     if (ModelState.IsValid)
     {
         User user = UsersRepository.GetUser(loginSignModel.LoginUser.Name, loginSignModel.LoginUser.Password);
         if (user != null)
         {
             HttpCookie cookie = new HttpCookie("SignInCookie");
             cookie.Value   = user.Id.ToString() + "," + user.FirstName;
             cookie.Expires = DateTime.Now.AddMinutes(10);
             this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
         }
         else
         {
             ViewBag.Error = "Username or password is incorrect";
         }
     }
     loginSignModel.Products = ProductsRepository.GetProducts();
     return(View(loginSignModel));
 }
Beispiel #7
0
        public ActionResult NewProfile(LoginSignModel loginSignModel)
        {
            ModelState.Remove(loginSignModel.SignInUser.UserName);
            if (ModelState.IsValid)
            {
                string[] cookie       = Request.Cookies["SignInCookie"].Value.Split(',');
                int      userId       = int.Parse(cookie[0]);
                User     userToUpdate = new User()
                {
                    Id        = userId,
                    FirstName = loginSignModel.SignInUser.FirstName,
                    LastName  = loginSignModel.SignInUser.LastName,
                    BirthDate = loginSignModel.SignInUser.BirthDate,
                    Email     = loginSignModel.SignInUser.Email,
                    UserName  = loginSignModel.SignInUser.UserName,
                    Password  = loginSignModel.SignInUser.Password
                };

                UsersRepository.Update(userToUpdate);
                Response.Cookies["SignInCookie"].Value = userId.ToString() + "," + userToUpdate.FirstName;
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Beispiel #8
0
        public ActionResult Index(string order)
        {
            List <Product> products = ProductsRepository.GetProducts();

            if (order == "name")
            {
                products = (from p in products
                            orderby p.Title
                            select p).ToList();
            }
            else if (order == "date")
            {
                products = (from p in products
                            orderby p.Date
                            select p).ToList();
            }

            var LoginSignModel = new LoginSignModel()
            {
                Products = products
            };

            return(View(LoginSignModel));
        }