public ActionResult EndSprint(int id = 0) { // for checking if the user allowed var adminproj = db.projects.Select(x => x).Where(x => x.id == id && x.projectleader == User.Identity.Name).FirstOrDefault(); if (adminproj == null) { return(RedirectToAction("Index", "project")); } // creating a new sprint MvcApplicationTest1.DAL.sprint sp = new DAL.sprint(); sp.date = DateTime.Now.ToString(); sp.projectid = id; // for giving the new sprint its id var zz = db.projects.Select(x => x).Where(x => x.id == id).FirstOrDefault(); var xx = db.sprints.Select(x => x).Where(x => x.sid == zz.currentsprint).FirstOrDefault(); sp.number = xx.number + 1; db.sprints.Add(sp); db.SaveChanges(); //for moving not completed issues to the next sprint var zz2 = db.columns.Select(x => x).Where(x => x.projectid == id).OrderByDescending(x => x.colid).FirstOrDefault(); var lastcolid = zz2.colid; //list of unfinished issues var zz3 = db.issues.Select(x => x).Where(x => x.projectid == id && x.status != lastcolid && x.sprintid == zz.currentsprint).ToList(); // it copies the unfinshed issue to a new issue and add it to the current sprint // and moves the unfinished issues to the new sprint for saving the change log foreach (var item in zz3) { MvcApplicationTest1.DAL.issue s = new MvcApplicationTest1.DAL.issue(); s.keyname = item.keyname; s.status = item.status; s.descreption = item.descreption; s.type = item.type; s.priority = item.priority; s.tags = item.tags; s.estimate = item.estimate; s.assignee = item.assignee; s.rankid = item.rankid; s.projectid = item.projectid; s.sprintid = zz.currentsprint; item.sprintid = sp.sid; db.issues.Add(s); db.SaveChanges(); } // make the new sprint the current sprint zz.currentsprint = sp.sid; db.SaveChanges(); MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream(); String username = Convert.ToString(Session["UserName"]); activitystr.actiontype = "End Sprint"; activitystr.description = username + " Ended Sprint Number " + xx.number; activitystr.issueid = 4; activitystr.issuekey = "-"; activitystr.actiondate = DateTime.Now.ToString(); activitystr.projectid = sp.projectid; int uid = int.Parse(Session["UserId"] + ""); activitystr.userid = uid; db.activitystreams.Add(activitystr); db.SaveChanges(); return(RedirectToAction("Indexproject", "Column", new { id = zz.id }));; }
public ActionResult Create(project project) { if (ModelState.IsValid) { UsersContext uc = new UsersContext(); var user = uc.UserProfiles.Select(x => x).Where(x => x.UserName == project.projectleader).FirstOrDefault(); project.projectleader = user.UserName; var user2 = uc.UserProfiles.Select(x => x).Where(x => x.UserName == project.projectowner).FirstOrDefault(); project.projectowner = user2.UserName; // for checking if the keyname is in use var pro = db.projects.Select(x => x).Where(x => x.projectkey == project.projectkey).FirstOrDefault(); if (pro != null) { ViewBag.ErrorMessage = "Key is in use"; var users = Roles.GetUsersInRole("teamleader"); SelectList list = new SelectList(users); ViewBag.Usersq = list; var users2 = Roles.GetUsersInRole("projectowner"); SelectList list2 = new SelectList(users2); ViewBag.Usersqq = list2; return(View(project)); } project.date = DateTime.Now.ToString(); db.projects.Add(project); db.SaveChanges(); // for creating the first sprint MvcApplicationTest1.DAL.sprint sp = new DAL.sprint(); sp.date = DateTime.Now.ToString(); sp.projectid = project.id; sp.number = 1; db.sprints.Add(sp); db.SaveChanges(); // for making the new sprint the projects first sprint project.currentsprint = sp.sid; db.SaveChanges(); Session["projectid"] = project.id; String username = Convert.ToString(Session["UserName"]); //for adding delete action to activity stream MvcApplicationTest1.DAL.activitystream activitystr = new MvcApplicationTest1.DAL.activitystream(); activitystr.actiontype = "Create Project"; activitystr.description = username + " Created Project " + project.projectname; activitystr.issueid = 4; activitystr.issuekey = "-"; activitystr.actiondate = DateTime.Now.ToString(); activitystr.projectid = project.id; int uid = int.Parse(Session["UserId"] + ""); activitystr.userid = uid; db.activitystreams.Add(activitystr); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(project)); }