public ActionResult Create(ProjectViewModel PVM) { Project P = new Project(); var currentUserId = User.Identity.GetUserId(); int myInt = int.Parse(currentUserId); User u = us.GetById(myInt); if (PVM.Start_Date >= DateTime.Now) { P.ProjectId = PVM.ProjectId; P.ProjectName = PVM.ProjectName; P.Description = PVM.Description; P.etat = Domain.Entities.Etat.Active; P.Duration = (PVM.End_Date - PVM.Start_Date).TotalDays.ToString(); P.Start_Date = PVM.Start_Date; P.End_Date = PVM.End_Date; P.TeamFK = u.TeamFK; ps.Add(P); ps.Commit(); return(RedirectToAction("index")); } else { ViewBag.Message = "Start date must be greater than Today !"; } return(View("Create")); }
// POST: api/WebApiProject public IHttpActionResult Post([FromBody] ProjectApiViewModel PVM) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } Project P = new Project(); P.ProjectId = PVM.ProjectId; P.ProjectName = PVM.ProjectName; P.Description = PVM.Description; P.etat = Domain.Entities.Etat.Active; P.Duration = (PVM.End_Date - PVM.Start_Date).TotalDays.ToString(); P.Start_Date = PVM.Start_Date; P.End_Date = PVM.End_Date; PS.Add(P); PS.Commit(); return(Ok(P)); }