예제 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    EmailAddressAttribute emailCheck = new EmailAddressAttribute();

                    if (emailCheck.IsValid(model.Email))
                    {
                        UserDataContext db = new UserDataContext();

                        CustSecurityController Secure = new CustSecurityController();
                        WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                        UserData dataProfile = new UserData(model.UserName, model.Email, model.Street, model.HouseNumber, model.City, model.PostalCode, null);

                        db.DBUserData.Add(dataProfile);
                        db.SaveChanges();

                        Secure.Create(new IPProfile(model.UserName, Request.UserHostAddress));
                        WebSecurity.Login(model.UserName, model.Password);
                        return RedirectToAction("Overview", "Page");
                    }
                    else
                    {
                        ModelState.AddModelError("", "The email address entered is not valid");
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #2
0
        public ActionResult RemoveFromCart(FormCollection collection)
        {
            Session["order"] = collection["order"].ToString();

            // Get logged in user
            UserDataContext uContext = new UserDataContext();
            UserData user;
            string userName = User.Identity.Name;
            var a = from x in uContext.DBUserData
                    where x.Username == userName
                    select x;
            user = a.ToList().First();

            user.Order = Session["order"].ToString();

            try
            {
                uContext.SaveChanges();
            }
            catch (Exception e)
            {
                return Json("The system was unable to save your order");
            }

            return Json(Session["order"]);
        }
예제 #3
0
        /// <summary>
        /// Simply, logs the user off.
        /// </summary>
        /// <returns>""</returns>
        public ActionResult LogOff()
        {
            // Ingelogde gebruiker ophalen
            UserDataContext uContext = new UserDataContext();
            UserData user;
            string userName = User.Identity.Name;
            var a = from x in uContext.DBUserData
                    where x.Username == userName
                    select x;
            user = a.ToList().First();

            user.Order = null;

            try
            {
                uContext.SaveChanges();
            }
            catch (Exception e)
            {
                return Json("The system was unable to save your order");
            }

            Session["order"] = null;

            WebSecurity.Logout();

            return RedirectToAction("Overview", "Page");
        }
예제 #4
0
        public ActionResult PhotoToCart(FormCollection collection)
        {
            if (collection["id"].Contains(',') == true)
                collection["id"].Remove(0, 1);
            int id = Convert.ToInt16(collection["id"]);

            // Get photo
            PicturesContext pContext = new PicturesContext();
            PictureModel photo = pContext.Picture.Find(id);

            // Get logged in user
            UserDataContext uContext = new UserDataContext();
            UserData user;
            string userName = User.Identity.Name;
            var a = from x in uContext.DBUserData
                    where x.Username == userName
                    select x;
            if (a.Any())
            {
                user = a.ToList().First();
            }
            else
            {
                return Json("The system was unable to save your order"); ;
            }

            var order = Session["order"];
            if (order == null)
            {
                Session["order"] = id.ToString();
            }
            else
            {
                Session["order"] = order + ", " + id;
            }
            order = Session["order"];

            user.Order = order.ToString();

            try
            {
                uContext.SaveChanges();
            }
            catch (Exception e)
            {
                return Json("The system was unable to save your order");
            }

            return Json(photo);
        }