Exemple #1
0
        public ActionResult Register(RegModel model)
        {
            if (ModelState.IsValid)
            {

                Repository repository = new Repository();

                if (repository.GetUser(model.Login) == null)
                {
                    repository.NewUser(model.Login, model.Password);

                    if (repository.GetUser(model.Login, model.Password) != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.Login, true);
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким логином уже существует");
                }
            }

            return View();
        }
Exemple #2
0
        public ActionResult DeleteAdvert(int id)
        {
            Repository repository = new Repository();

                var user = repository.GetUser(User.Identity.Name);
                var advert = repository.GetAdvert(id);

                if ( repository.GetAdvert(id) != null)
                {
                    if(user.Id == advert.UserId)
                    {
                        repository.DeleteAdvert(advert);

                        return RedirectToAction("Index", "Home");
                    }
                    return RedirectToAction("Login", "Account");// нет прав
                }
                return RedirectToAction("Index", "Home");// объявления не найдено
        }
Exemple #3
0
        public ActionResult Login(LogModel model)
        {
            if (ModelState.IsValid)
            {

                Repository repository = new Repository();

                if (repository.GetUser(model.Login, model.Password) != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Login, true);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Пользователя с таким логином и паролем нет");
                }
            }

            return View();
        }
Exemple #4
0
        public ActionResult EditAdvert(int id)
        {
            ViewBag.AdvertID = id;
            Repository repository = new Repository();

            var user = repository.GetUser(User.Identity.Name);
            var advert = repository.GetAdvert(id);

            if (user.Id == advert.UserId)
            {
                var model = new EditModel()
                {
                    AdvertID = advert.AdvertID,
                    Description = advert.Description,
                    Title = advert.Title
                };
                return View(model);
            }
            return RedirectToAction("Index", "Home");
        }
Exemple #5
0
        public ActionResult EditAdvert(EditModel model)
        {
            Repository repository = new Repository();

            var user = repository.GetUser(User.Identity.Name);

            if (repository.GetAdvert(model.AdvertID) != null)
            {
                if (user.Id == repository.GetAdvert(model.AdvertID).UserId)
                {
                    repository.EditAdvert(model);
                    return RedirectToAction("Index", "Home");
                }

                return RedirectToAction("Login", "Account");// нет прав
            }
            return RedirectToAction("Index", "Home");// объявления нет
        }