public IHttpActionResult Post(FormationVM FormationVM) { //if (!ModelState.IsValid) // return BadRequest("Invalid data."); using (var ctx = new MyContext()) { ctx.Formations.Add(new Formation() { Title = FormationVM.Title, Start = DateTime.UtcNow, End = FormationVM.End, Description = FormationVM.Description, Affiche = FormationVM.Affiche, NbrMax = FormationVM.NbrMax, Theme = FormationVM.Theme, Location = FormationVM.Location, Price = FormationVM.Price, // nomuser = User.Identity.GetUserName(), UserId = "f43c21cf-f35a-4897-a9e3-343c00afe7b3" }); ctx.SaveChanges(); } return(Ok()); }
// PUT api/<controller>/5 public IHttpActionResult Put(FormationVM FormationVM) { //if (!ModelState.IsValid) // return BadRequest("Not a valid model"); using (var ctx = new MyContext()) { var existingFormation = ctx.Formations.Where(s => s.FormationID == FormationVM.FormationID) .FirstOrDefault <Formation>(); if (existingFormation != null) { existingFormation.Title = FormationVM.Title; existingFormation.Start = DateTime.UtcNow; existingFormation.End = FormationVM.End; existingFormation.Description = FormationVM.Description; existingFormation.Affiche = FormationVM.Affiche; existingFormation.NbrMax = FormationVM.NbrMax; existingFormation.Theme = FormationVM.Theme; existingFormation.Location = FormationVM.Location; existingFormation.Price = FormationVM.Price; ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public ActionResult Edit(int id, FormationVM pm, HttpPostedFileBase Affiche) { try { Formation p = MyFormationService.GetById((int)id); p.Start = pm.Start; p.End = pm.End; p.Description = pm.Description; p.Affiche = Affiche.FileName; p.UserId = pm.UserId; p.FormationID = pm.FormationID; p.Theme = pm.Theme; p.Title = pm.Title; p.Location = pm.Location; p.NbrMax = pm.NbrMax; p.Price = pm.Price; MyFormationService.Update(p); MyFormationService.Commit(); var path = Path.Combine(Server.MapPath("~/Content/Uploads"), Affiche.FileName); Affiche.SaveAs(path); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(pm)); } }
public ActionResult Create(FormationVM FormationVM, HttpPostedFileBase Affiche) { if (!ModelState.IsValid || Affiche == null || Affiche.ContentLength == 0) { RedirectToAction("Create"); } Formation FormationDomain = new Formation() { Title = FormationVM.Title, Start = DateTime.UtcNow, End = FormationVM.End, Description = FormationVM.Description, Affiche = Affiche.FileName, NbrMax = FormationVM.NbrMax, Theme = FormationVM.Theme, Location = FormationVM.Location, Price = FormationVM.Price, // nomuser = User.Identity.GetUserName(), UserId = "f43c21cf-f35a-4897-a9e3-343c00afe7b3" }; MyFormationService.Add(FormationDomain); MyFormationService.Commit(); var path = Path.Combine(Server.MapPath("~/Content/Uploads"), Affiche.FileName); Affiche.SaveAs(path); return(RedirectToAction("Index")); }
// GET: Formation/Details/5 public ActionResult Details(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Formation p; p = MyFormationService.GetById((int)id); if (p == null) { return(HttpNotFound()); } FormationVM pvm = new FormationVM() { FormationID = p.FormationID, Title = p.Title, Affiche = p.Affiche, Start = p.Start, End = p.End, Description = p.Description, Location = p.Location, Price = p.Price, Theme = p.Theme, NbrMax = p.NbrMax }; var t = MyActiviteService.GetMany(); foreach (Activite A in t) { if (string.IsNullOrEmpty(A.Affiche)) { var path = Path.Combine(Server.MapPath("~/Content/Front/images/event/event_02.jpg")); KalikoImage image = new KalikoImage(path); KalikoImage thumb = image.Scale(new CropScaling(90, 80)); var path2 = Path.Combine(Server.MapPath("~/Content/Uploads"), A.Title + "latest.jpg"); thumb.SaveJpg(path2, 99); A.Affiche = A.Title + "latest.jpg"; } else { var path = Path.Combine(Server.MapPath("~/Content/Uploads"), A.Affiche); KalikoImage image = new KalikoImage(path); KalikoImage thumb = image.Scale(new CropScaling(90, 80)); var path2 = Path.Combine(Server.MapPath("~/Content/Uploads"), A.Title + "latest.jpg"); thumb.SaveJpg(path2, 99); A.Affiche = A.Title + "latest.jpg"; } } List <Activite> Courses = t.ToList(); ViewData["Courses"] = Courses; return(View(pvm)); }
public JsonResult SaveEvent(FormationVM e) { var status = false; if (e.FormationID > 0) { //Update the event Formation v = MyFormationService.GetById(e.FormationID); if (v != null) { v.Title = e.Title; v.Start = (DateTime)e.Start; v.End = e.End; v.Description = e.Description; // v.IsFullDay = e.IsFullDay; v.Theme = e.Theme; v.Price = e.Price; v.Location = e.Location; v.NbrMax = e.NbrMax; v.Affiche = e.Affiche; // v.UserId = User.Identity.GetUserId(); MyFormationService.Update(v); } } else { Formation v = new Formation() { Title = e.Title, Start = e.Start, End = e.End, Description = e.Description, Affiche = e.Affiche, NbrMax = e.NbrMax, Theme = e.Theme, Location = e.Location, Price = e.Price, // nomuser = User.Identity.GetUserName(), UserId = "f43c21cf-f35a-4897-a9e3-343c00afe7b3" }; MyFormationService.Add(v); } MyFormationService.Commit(); status = true; return(new JsonResult { Data = new { status = status } }); }
public ActionResult AddOrEditFormation(FormationVM formation) { int userId = int.Parse(HttpContext.User.Identity.Name); if (ModelState.IsValid) //Despite its name, it doesn't actually know anything about any model classes. //The ModelState represents a Enumerable of name and value pairs that were submitted to the server during a POST. //It also contains a Enumerable of error messages for each value submitted { if (formation.FormAction == "AjoutTraitement") { Formation forma = new Formation(); forma.DateDebut = formation.DateDebut; forma.DateFin = formation.DateFin; forma.Ecole = formation.Ecole; forma.Description = formation.Description; forma.Diplome = formation.Diplome; forma.PersonneId = userId; using (Context context = new Context()) { context.Formations.Add(forma); context.SaveChanges(); } } else if (formation.FormAction == "EditionTraitement") { using (Context context = new Context()) { var result = (from f in context.Formations where f.Id == formation.Id && f.PersonneId == userId select f).SingleOrDefault(); if (result != null) { result.DateDebut = formation.DateDebut; result.DateFin = formation.DateFin; result.Ecole = formation.Ecole; result.Description = formation.Description; result.Diplome = formation.Diplome; context.SaveChanges(); } } } } return(RedirectToAction("Formations")); }
// GET: Formation/Edit/5 public ActionResult Edit(int id) { Formation p = MyFormationService.GetById((int)id); FormationVM pm = new FormationVM() { Start = p.Start, End = p.End, Description = p.Description, Affiche = p.Affiche, UserId = p.UserId, FormationID = p.FormationID, Theme = p.Theme, Title = p.Title, Location = p.Location, NbrMax = p.NbrMax, Price = p.Price }; return(View(pm)); }