public ViewResult AddAd() { AddAdViewModel model = new AddAdViewModel { Types = GetTypesOfProperty() }; return(View(model)); }
public ActionResult AddAd(AddAdViewModel model) { if (!ModelState.IsValid) { model.Types = GetTypesOfProperty(); return(View(model)); } Advert advert = new Advert { Name = model.Name, Town = model.Town, Description = model.Description, Price = model.Price, Date = DateTime.Now, Type = new AdType { ID = model.TypeID }, Status = model.Status, User = new ApplicationUser { Id = User.Identity.GetUserId() } }; Photo newPhoto = SavePhoto(model.NewPhoto); if (newPhoto != null) { advert.Photos = new List <Photo> { newPhoto }; } Int32 modelID = _repository.SaveAdvert(advert); return(RedirectToAction("Ad", new { adId = modelID })); }