public IActionResult Update(int id, EditAdViewModel model) { ViewData["Cats"] = _databaseContext.AdCategory.ToList(); if (id != 0) { model.Id = id; } if (ModelState.IsValid) { var ses = _databaseContext.Ad.Include(p => p.AdCategory).FirstOrDefault(m => m.Id == id); ses.AdCategory = _databaseContext.AdCategory.ToList().First(c => c.Id == model.AdCategoryId); ses.JobSummary = model.JobSummary; ses.Location = model.Location; ses.NumberOfWorkingHours = model.NumberOfWorkingHours; ses.RequiredSkills = model.RequiredSkills; ses.Title = model.Title; TempData["Success"] = true; _databaseContext.SaveChanges(); TempData[Constants.Message] = $"Oglas je promijenjen"; TempData[Constants.ErrorOccurred] = false; return(RedirectToAction(nameof(Index))); } else { ViewData["Cats"] = _databaseContext.AdCategory.ToList(); return(View("Edit", model)); } }
// GET: Ad/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } Ad ad = await _context.Ads .Include(a => a.RealEstateStatus) .Include(a => a.RealEstateType) .Include(a => a.Town) .SingleOrDefaultAsync(x => x.AdID == id); if (ad == null) { return(NotFound()); } EditAdViewModel viewModel = new EditAdViewModel { Ad = ad, SelectedStatus = ad.RealEstateStatus.RealEstateStatusID, StatusList = await _context.RealEstateStatuses.ToListAsync(), Towns = new SelectList(_context.Towns, "TownID", "Name"), Types = new SelectList(_context.RealEstateTypes, "RealEstateTypeID", "Name"), }; return(View(viewModel)); }
public async Task <IActionResult> Edit(int id, EditAdViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var user = await this.userManager.GetUserAsync(this.User); var ad = await this.ads.FindForEdit(id); if (user.Id != ad.UserId) { return(this.BadRequest()); } var success = await this.ads.Edit( model.Name, model.Description, model.AdProfilePicUrl, model.Website, user.Id, id); if (!success) { return(this.BadRequest()); } this.TempData.AddSuccessMessage($"Ad {model.Name} details have been successfully changed."); return(this.RedirectToAction("Ad", "Users", new { Area = "", id = id })); }
public ViewResult Edit(Int32 id) { var data = _repository.GetById(id); if (data == null) { return(View("Error404")); } if (User.Identity.GetUserId() != data.User.Id) { return(View("AccessError")); } EditAdViewModel model = new EditAdViewModel { Id = id, Name = data.Name, Description = data.Description, Price = data.Price, Status = data.Status, TypeID = data.Type.ID, Town = data.Town, Types = GetTypesOfProperty(), OldPhoto = GetPhotosOfAdvert(data, PhotoSize.Small)[0] }; return(View(model)); }
public async Task <IActionResult> Edit(long id, [Bind("Title,Description")] EditAdViewModel editAdViewModel) { var ad = await _context.Ads.FindAsync(id); if (ad == null) { return(NotFound()); } if (ModelState.IsValid) { try { ad.Title = editAdViewModel.Title; ad.Description = editAdViewModel.Description; ad.Modified = DateTime.Now; _context.Update(ad); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdExists(ad.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ad)); }
private EditAdViewModel GetEditAdViewModel(EditAdDetailsViewModel editAdDetailsViewModel, EditAdAddressViewModel editAdAddressViewModel) { var editAdViewModel = new EditAdViewModel { EditAdDetailsViewModel = editAdDetailsViewModel, EditAdAddressViewModel = editAdAddressViewModel }; return(editAdViewModel); }
public IActionResult EditAdvertisement(int id) { var advertisements = _context.Advertisements.FirstOrDefault(x => x.Id == id); EditAdViewModel editAdViewModel = new EditAdViewModel { Id = advertisements.Id, Title = advertisements.Title, Description = advertisements.Description, AdTypes = advertisements.AdTypes }; return(View(editAdViewModel)); }
public ActionResult Edit(EditAdViewModel model, Int32 id) { var data = _repository.GetById(id); if (data == null) { return(View("Error404")); } if (User.Identity.GetUserId() != data.User.Id) { return(View("AccessError")); } if (!ModelState.IsValid) { model.Types = GetTypesOfProperty(); model.Id = id; model.OldPhoto = GetPhotosOfAdvert(data, PhotoSize.Small)[0]; return(View(model)); } Advert advert = new Advert { ID = id, Name = model.Name, Date = DateTime.Now, Description = model.Description, Price = model.Price, Town = model.Town, Status = model.Status, Type = new AdType { ID = model.TypeID } }; 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 })); }
public IActionResult EditAdvertisement(EditAdViewModel model) { var advertisement = _context.Advertisements.FirstOrDefault(x => x.Id == model.Id); if (advertisement == null) { return(View()); } else { advertisement.Id = model.Id; advertisement.Description = model.Description; advertisement.Title = model.Title; advertisement.AdTypes = model.AdTypes; _context.SaveChanges(); return(RedirectToAction("UserAds")); } }
public void LoadView(MainWindowViewType typeView, Advert ad) { switch (typeView) { case MainWindowViewType.EditAd: EditAdPage viewEditAd = new EditAdPage(); EditAdViewModel vmEditAd = new EditAdViewModel(this, ad); viewEditAd.DataContext = vmEditAd; this.OutputView.Content = viewEditAd; break; case MainWindowViewType.Advert: AdvertPage viewAdvert = new AdvertPage(); AdvertPageViewModel vmAdvert = new AdvertPageViewModel(this, ad); viewAdvert.DataContext = vmAdvert; this.OutputView.Content = viewAdvert; break; } }
public async Task <IActionResult> Edit(int id, EditAdViewModel viewModel) { if (id != viewModel.Ad.AdID) { return(NotFound()); } if (ModelState.IsValid) { viewModel.Ad.DateInit = DateTime.Now; viewModel.Ad.RealEstateStatusID = viewModel.SelectedStatus; _context.Update(viewModel.Ad); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public ViewResult Edit(int id) { ViewData["Cats"] = _databaseContext.AdCategory.ToList(); var ses = _databaseContext.Ad.Include(t => t.AdCategory) .FirstOrDefault(p => p.Id == id); ViewData["Success"] = TempData["Success"]; var model = new EditAdViewModel { JobSummary = ses.JobSummary, Id = ses.Id, Location = ses.Location, NumberOfWorkingHours = ses.NumberOfWorkingHours, RequiredSkills = ses.RequiredSkills, Title = ses.Title }; return(View(model)); }
public ActionResult EditAd(EditAdViewModel post) { StoredProcs.Ads_CreateOrUpdateAd(post.Ad.BodyHtml, post.Ad.Id).Execute(); return(RedirectToAction("index")); }
public ActionResult EditAd(EditAdViewModel post) { DB.Ads_CreateOrUpdateAd(post.Ad.BodyHtml, post.Ad.Id); return(RedirectToRoute("FooterAdListAdmin")); }