示例#1
0
        public ActionResult Login(Login user)
        {
            if (ModelState.IsValid)
            {
                if (!Authentication.ValidateUser(user.Username, user.Password))
                {
                    ModelState.AddModelError("ValidateErr", "The username and/or password were entered incorrectly.");
                    return View(user);
                }
                UserProfile profile = db.UserProfiles.Where(x => x.Username == user.Username).FirstOrDefault();

                var profileData = new UserProfileSessionData
                {
                    ProfileId = profile.ProfileId,
                    City = profile.City,
                    Username = profile.Username
                };

                Response.SetAuthCookie(user.Username, user.RememberMe, profileData);

                if (profileData.City == "N/A")
                {
                    return RedirectToAction("SelectCity");
                }
                else
                {
                    return RedirectToAction("Index", "Profile");
                }
            }
            return View(user);
        }
示例#2
0
        public ActionResult AddSearch(AddEditSearchVM vm)
        {
            profileData = AuthCookies.DeserializeCookie<UserProfileSessionData>(HttpContext.Request.Cookies["authenticationToken"]);
            try
            {
                if (ModelState.IsValid)
                {
                    SearchCriteria sc = new SearchCriteria
                    {
                        ProfileId = profileData.ProfileId,
                        SearchText = vm.SearchText,
                        MinPrice = vm.MinPrice,
                        MaxPrice = vm.MaxPrice,
                    };

                    db.AddEntry(sc);

                    List<CategorySearch> catSearch = new List<CategorySearch>();
                    foreach (CheckBoxCategoryVM c in vm.Categories.Where(w => w.IsChecked))
                    {
                        string http = RssPages.BuildHttp(vm, c.Code, profileData.City);
                        catSearch.Add(new CategorySearch { SearchId = sc.SearchId, Category = c.Code, SearchLink = http });
                    }

                    db.AddEntries(catSearch);
                }
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError("", "Unable to save changes. Please try again. If the same error keeps occurring, try again another time.");
            }

            return RedirectToAction("Index");
        }
示例#3
0
        public static void UpdateCityForProfile(this CLContext db, UserProfileSessionData profileData)
        {
            UserProfile profile = db.UserProfiles.Find(profileData.ProfileId);
            profile.City = profileData.City;

            db.UserProfiles.Attach(profile);
            var entry = db.Entry(profile);

            entry.Property(e => e.City).IsModified = true;
            db.SaveChanges();
        }
示例#4
0
        private void CreateCookie(UserProfile profile, bool rememberMe)
        {
            var profileData = new UserProfileSessionData
            {
                ProfileId = profile.ProfileId,
                City = profile.City,
                Username = profile.Username,
                IsPersistent = rememberMe
            };

            Response.SetAuthCookie(profile.Username, rememberMe, profileData);
        }
示例#5
0
        // GET: Profile
        public ActionResult Index()
        {
            profileData = AuthCookies.DeserializeCookie<UserProfileSessionData>(HttpContext.Request.Cookies["authenticationToken"]);

            ViewBag.User = profileData.Username;
            List<AddEditSearchVM> searches = Procedures.GetAddEditSearchVMByProfileId(profileData.ProfileId);

            return View(searches.GroupBy(g => g.SearchId).Select(s => s.First()).ToList());
        }
示例#6
0
        public ActionResult EditSearch(AddEditSearchVM vm, AddEditSearchVM oldState, int id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    profileData = AuthCookies.DeserializeCookie<UserProfileSessionData>(HttpContext.Request.Cookies["authenticationToken"]);
                    AddEditSearchVM previousState = Procedures.GetAddEditSearchVMBySearchId(id);

                    List<UpdateCategories> updateCategories = new List<UpdateCategories>();
                    foreach (CheckBoxCategoryVM cat in vm.Categories)
                    {
                        CheckBoxCategoryVM previousCat = new CheckBoxCategoryVM();
                        previousCat = previousState.Categories.FirstOrDefault(s => s.Code == cat.Code) ?? null;

                        if (cat.IsChecked && previousCat == null)
                        {
                            string http = RssPages.BuildHttp(vm, cat.Code, profileData.City);
                            updateCategories.Add(new UpdateCategories()
                            {
                                Category = cat.Code,
                                InsertOrDelete = cat.IsChecked,
                                SearchLink = http
                            });
                        }

                        if (previousCat != null && previousCat.IsChecked && !cat.IsChecked)
                        {
                            updateCategories.Add(new UpdateCategories()
                            {
                                Category = previousCat.Code,
                                InsertOrDelete = false
                            });
                        }
                    }

                    Procedures.UpdateSearchCriteria(id,
                        vm.SearchText,
                        vm.MinPrice ?? default(decimal),
                        vm.MaxPrice ?? default(decimal),
                        updateCategories);
                }
            }
            catch (RetryLimitExceededException)
            {
                ModelState.AddModelError("", "Unable to save changes. Please try again. If the same error keeps occurring, try again another time.");
            }

            return RedirectToAction("Index");
        }