Ejemplo n.º 1
0
        public void EditAdvert(EditModel _model)
        {
            Advert advert = db.Adverts.FirstOrDefault(a => a.AdvertID == _model.AdvertID);

            if (_model.Title != null)
            {
                advert.Title = _model.Title;
            }
            if (_model.Description != null)
            {
                advert.Description = _model.Description;
            }
            if (_model.Image != null)
            {
                System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + advert.ImagePath);
                _model.Image.SaveAs(AppDomain.CurrentDomain.BaseDirectory + advert.ImagePath);
            }
            db.SaveChanges();
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
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");// объявления нет
        }