public ActionResult DeleteConfirmed(decimal id) { AvantageSociaux avantageSociaux = db.AvantageSociaux.Find(id); avantageSociaux.archived = 0; db.Entry(avantageSociaux).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(AvantageSociaux avantageSociaux) { var currentAvantageSociaux = db.AvantageSociaux.FirstOrDefault(p => p.id == avantageSociaux.id); if (currentAvantageSociaux == null) { return(HttpNotFound()); } if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { try { var filename = Path.GetFileName(file.FileName); //verification de l'extention du fichiers var supportedTypes = new[] { ".png", ".jpg", ".jpeg", ".gif" }; var extention = Path.GetExtension(filename); if (!supportedTypes.Contains(extention)) { ViewBag.ErrorFile = "L'extention du fichier n'est pas valide !"; return(View(avantageSociaux)); } //end verification var formattedFilename = string.Format("{0}-{1}{2}" , Path.GetFileNameWithoutExtension(filename) , Guid.NewGuid().ToString("N") , Path.GetExtension(filename)); string path = Path.Combine(Server.MapPath("~/Fichier"), Path.GetFileName(formattedFilename)); file.SaveAs(path); currentAvantageSociaux.image = formattedFilename; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); return(View(avantageSociaux)); } } } currentAvantageSociaux.image = avantageSociaux.image; currentAvantageSociaux.libelle = avantageSociaux.libelle; currentAvantageSociaux.description = avantageSociaux.description; db.Entry(currentAvantageSociaux).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(AvantageSociaux avantageSociaux) { if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { try { var filename = Path.GetFileName(file.FileName); //verification de l'extention du fichiers var supportedTypes = new[] { ".png", ".jpg", ".jpeg", ".gif" }; var extention = Path.GetExtension(filename); if (!supportedTypes.Contains(extention)) { ViewBag.ErrorFile = "L'extention du fichier n'est pas valide !"; return(View(avantageSociaux)); } //end verification var formattedFilename = string.Format("{0}-{1}{2}" , Path.GetFileNameWithoutExtension(filename) , Guid.NewGuid().ToString("N") , Path.GetExtension(filename)); string path = Path.Combine(Server.MapPath("~/Fichier"), Path.GetFileName(formattedFilename)); file.SaveAs(path); avantageSociaux.image = formattedFilename; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); return(View(avantageSociaux)); } } } if (ModelState.IsValid) { avantageSociaux.archived = 1; avantageSociaux.status = 1; avantageSociaux.created = DateTime.Now; db.AvantageSociaux.Add(avantageSociaux); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(avantageSociaux)); }
// GET: AvantageSociauxes/Details/5 public ActionResult Details(decimal id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AvantageSociaux avantageSociaux = db.AvantageSociaux.Find(id); if (avantageSociaux == null) { return(HttpNotFound()); } return(View(avantageSociaux)); }
protected Dictionary <string, Object> getJson(AvantageSociaux item) { var json = new Dictionary <string, Object>(); if (item == null) { return(null); } json.Add("id", item.id); json.Add("libelle", item.libelle); json.Add("name", item.libelle); json.Add("description", item.description); json.Add("image", MsMail.baseUrl + "Fichier/" + item.image); //json.Add("status", item.status); return(json); }