public IHttpActionResult PostProject(ProjectModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var project = new Project(); project.Name = model.Name; project.Description = model.Description; _services.Add(project); return(Ok(project)); }
public ActionResult Create(ProjectViewModel PVM) { if (!Request.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } //redirect to nowhere if not admin if (!(User.IsInRole("Team Leader"))) { return(RedirectToAction("Nowhere", "Account")); } 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.Date) { P.ProjectId = PVM.ProjectId; P.ProjectName = PVM.ProjectName; P.Description = PVM.Description; P.etat = Domain.Entities.Etat.Pending; 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")); }