public ActionResult Desactiver(int id) { tb_ads ad = annoncesRepository.GetById(id); if (ad == null) { throw new HttpException(404, "Annonce not found"); } ad.ad_status = 3; // set to pending ad.ad_is_published = 0; annoncesRepository.Update(ad); annoncesRepository.Save(); return(RedirectToAction("Index", "Annonces", new { area = "Admin" })); }
public ActionResult Modifier(ModifierAdsViewModel model) { if (ModelState.IsValid) { tb_ads ad = annoncesRepository.GetById(model.id_ad); if (ad == null) { throw new HttpException(404, "Annonce not found"); } int?section = catRepository.GetAll().Where(c => c.id_category == model.id_category).FirstOrDefault().id_section; try { ad.ad_title = model.ad_title; ad.ad_description = model.ad_description; ad.ad_price = (double)model.ad_price; ad.id_devise = model.id_devise; ad.id_section = (int)section; ad.id_category = model.id_category; ad.ad_phone = ad.ad_phone; annoncesRepository.Update(ad); annoncesRepository.Save(); return(RedirectToAction("Index", "MesAnnonces")); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0},{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } ModelState.AddModelError("", raise.Message); ViewBag.selected_devise = new SelectList(deviseRepository.GetAll(), "id_devise", "description", (object)model.id_devise); ViewBag.selected_category = this.populateCategoryBySection(); return(View(model)); } catch (Exception exp) { ModelState.AddModelError("", exp.Message); ViewBag.selected_devise = new SelectList(deviseRepository.GetAll(), "id_devise", "description", (object)model.id_devise); ViewBag.selected_category = this.populateCategoryBySection(); return(View(model)); } } ModelState.AddModelError("", "model not valid"); ViewBag.selected_devise = new SelectList(deviseRepository.GetAll(), "id_devise", "description", (object)model.id_devise); ViewBag.selected_category = this.populateCategoryBySection(); return(View(model)); }