public ActionResult Create(Project model, FormCollection collection) { var users = _db.Users.Where(u => u.IsDeleted == false).Select(u => u.UserID).ToList(); var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(_db)); try { string productOwner = collection["ProductOwners"]; string scrumMaster = collection["ScrumMasters"]; if (!string.IsNullOrEmpty(productOwner)) model.ProductOwnerID = Convert.ToInt64(productOwner); if (!string.IsNullOrEmpty(scrumMaster)) model.ScrumMasterID = Convert.ToInt64(scrumMaster); List<ProjectTeam> projectTeam = new List<ProjectTeam>(); model.Status = "Yet To Start"; model.Phase = string.Empty; if (ModelState.IsValid) { _db.Projects.Add(model); _db.SaveChanges(); // add project team members foreach (var userId in users) { if (collection[userId.ToString()] == "on") { projectTeam.Add(new ProjectTeam() { ProjectID = model.ProjectID, UserID = userId }); } } if(projectTeam.Count >0) { _db.TeamProjects.AddRange(projectTeam); _db.SaveChanges(); } // add Project Activites AddProjectActivties(model.ProjectID); return RedirectToAction("Index"); } else { return RedirectToAction("Create"); } // TODO: Add insert logic here } catch { return View(); } }
public ActionResult Edit(long id,Project model, FormCollection collection) { try { var users = _db.Users.Where(u => u.IsDeleted == false).Select(u => u.UserID).ToList(); var project = _db.Projects.Where(p => p.ProjectID == id).First(); List<ProjectTeam> projectTeam = new List<ProjectTeam>(); project.Name = model.Name; project.StartDate = model.StartDate; project.ExpectedEndDate = model.ExpectedEndDate; project.EndDate = model.EndDate; project.Description = model.Description; string productOwner = collection["ProductOwners"]; string scrumMaster = collection["ScrumMasters"]; if (!string.IsNullOrEmpty(productOwner)) model.ProductOwnerID = Convert.ToInt64(productOwner); if (!string.IsNullOrEmpty(scrumMaster)) model.ScrumMasterID = Convert.ToInt64(scrumMaster); _db.Entry(project).State = EntityState.Modified; _db.SaveChanges(); _db.TeamProjects.RemoveRange(project.ProjectTeam); _db.SaveChanges(); foreach (var userId in users) { if (collection[userId.ToString()] == "on") { projectTeam.Add(new ProjectTeam() { ProjectID = model.ProjectID, UserID = userId }); } } if (projectTeam.Count > 0) { _db.TeamProjects.AddRange(projectTeam); _db.SaveChanges(); } // TODO: Add update logic here return RedirectToAction("Index"); } catch { return View(); } }