public static List <Meeting> GetMeetingsByEmail(string email, int sprintID, int projectID = 0) { try { using (var context = new DatabaseContext()) { var meetingList = new List <Meeting>(); if (sprintID == -1) { meetingList = (from meeting in context.Meetings where ((meeting.Developer == email || meeting.ScrumMaster == email || meeting.Developer.Contains("," + email + ",")) && meeting.ProjectID == projectID) select meeting).ToList(); } else { meetingList = (from meeting in context.Meetings where (meeting.Developer == email || meeting.ScrumMaster == email || meeting.Developer.Contains("," + email + ",")) && meeting.SprintID == sprintID select meeting).ToList(); } return(meetingList); } } catch (Exception e) { SharedManager.Log(e, "GetMeetingsByEmail"); return(new List <Meeting> { }); } }
public static Project GetProjectByEmail(string email) { try { using (var context = new DatabaseContext()) { var projects = (from proj in context.Projects select proj).ToList(); Project project = null; foreach (var proj in projects) { if (proj.ScrumMaster == email || proj.DevTeam.Contains(email)) { project = proj; } } return(project); } } catch (Exception e) { SharedManager.Log(e, "GetProjectByEmail"); return(null); } }
public static Meeting Add_Meeting_Notes(Meeting meeting) { try { using (var context = new DatabaseContext()) { var meetingReturn = (from meet in context.Meetings where meet.MeetingID == meeting.MeetingID select meet).FirstOrDefault(); if (meetingReturn == null) { return(new Meeting()); } if (meetingReturn.MeetingType == "Scrum Meeting") { meetingReturn.Notes = meeting.Notes; } else { meetingReturn.Notes += ".NOTE_SEPARATOR." + meeting.Notes; } context.SaveChanges(); return(meetingReturn); } } catch (Exception e) { SharedManager.Log(e, "Add_Meeting_Notes"); return(new Meeting()); } }
private static string AddItemToSprint(int sprintID, int itemID) { try { using (var context = new DatabaseContext()) { var sprintReturn = (from sprint in context.Sprints where sprint.SprintID == sprintID select sprint).FirstOrDefault(); if (sprintReturn == null) { return("Sprint does not exist"); } sprintReturn.Items += itemID + ","; context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "AddItemToSprint"); return(SharedManager.DatabaseError); } }
public static string ChangeStatus(Item item) { try { using (var context = new DatabaseContext()) { var itemRet = (from it in context.Items where it.ItemID == item.ItemID select it).First(); itemRet.ItemStatus = item.ItemStatus; if (item.ItemStatus == "Closed" && itemRet.DateClosed == null) { itemRet.DateClosed = DateTime.Now; } else if (item.ItemStatus != "Closed") { itemRet.DateClosed = null; } itemRet.AssignedTo = item.AssignedTo; context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "Change_Status"); return(SharedManager.DatabaseError); } }
//private static int GetNewItemNumber() //{ // try // { // using (var context = new DatabaseContext()) // { // var count = context.Items.Count(); // if (count == 0) // return 1; // return count + 1; // } // } // catch (Exception e) // { // SharedManager.Log(e, "GetNewItemNumber"); // return -1; // } //} public static List <Item> GetItemsFromSprint(string items) { if (items == null) { return new List <Item>() { } } ; try { using (var context = new DatabaseContext()) { var itemList = SharedManager.SplitString(items); var itemRet = (from item in context.Items where itemList.Contains(item.ItemID.ToString()) select item).ToList(); itemRet = itemRet.OrderBy(d => itemList.IndexOf(d.ItemID.ToString())).ToList(); return(itemRet); } } catch (Exception e) { SharedManager.Log(e, "GetItemsFromSprint"); return(new List <Item>() { }); } }
public static string RegisterUser(Register user) { if (user == null) { return("Error when adding. Please try again"); } else if (CheckExistingEmail(user.Email)) { return("Email already in use"); } else { try { using (var context = new DatabaseContext()) { var insertUser = new User { Username = user.Username, Password = Hash(user.Password), Email = user.Email, Role = user.Role }; context.Users.Add(insertUser); context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "RegisterUser"); return(SharedManager.DatabaseError); } } }
public static bool CheckExistingEmail(string email) { try { using (var context = new DatabaseContext()) { var userEmails = from user in context.Users select user.Email; foreach (var Email in userEmails) { if (Email.Equals(email)) { return(true); } } return(false); } } catch (Exception e) { SharedManager.Log(e, "CheckExistingEmail"); return(false); } }
public static User GetUserByEmail(string Email) { try { var returnedUser = new User(); using (var context = new DatabaseContext()) { var userResult = (from user in context.Users where user.Email == Email select user).FirstOrDefault(); if (userResult != null) { returnedUser.Email = userResult.Email; returnedUser.Username = userResult.Username; returnedUser.Password = userResult.Password; returnedUser.Role = userResult.Role; } return(returnedUser); } } catch (Exception e) { SharedManager.Log(e, "GetUserByUsername"); return(null); } }
public static Sprint GetSprintFromID(int id) { try { var returnSprint = new Sprint(); using (var context = new DatabaseContext()) { var sprintResult = (from sprint in context.Sprints where sprint.SprintID == id select sprint).FirstOrDefault(); if (sprintResult == null) { return(returnSprint); } returnSprint.SprintID = sprintResult.SprintID; returnSprint.FinishDate = sprintResult.FinishDate; returnSprint.StartDate = sprintResult.StartDate; returnSprint.SprintNumber = sprintResult.SprintNumber; returnSprint.SprintName = sprintResult.SprintName; returnSprint.Items = sprintResult.Items; //returnSprint.ItemsList = sprintResult.Items.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); return(returnSprint); } } catch (Exception e) { SharedManager.Log(e, "GetSprintFromID"); return(null); } }
public static string AddMeetingQuestions(int id, Meeting meeting) { try { using (var context = new DatabaseContext()) { var meetingRet = (from meet in context.Meetings where (meet.MeetingID == meeting.MeetingID) && meet.SprintID == id select meet).First(); meetingRet.TodayQuestion = meeting.TodayQuestion; meetingRet.YesterdayQuestion = meeting.YesterdayQuestion; meetingRet.ObstaclesQuestion = meeting.ObstaclesQuestion; context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "AddMeetingQuestions"); return(SharedManager.DatabaseError); } }
public static string AddProject(Project project, string scrumMaster, out Project pr) { pr = new Project(); if (project == null) { return("Error when adding. Please try again"); } try { using (var context = new DatabaseContext()) { var proj = (from p in context.Projects where p.Name == project.Name select p).FirstOrDefault(); if (proj != null) { return(project.Name + " is already being used"); } scrumMaster = project.ScrumMaster ?? scrumMaster; var insertProject = new Project { Name = project.Name, ScrumMaster = scrumMaster, DevTeam = project.DevTeam, Description = project.Description }; if (!UserManager.CheckExistingEmail(insertProject.ScrumMaster)) { return(insertProject.ScrumMaster + " does not exist"); } insertProject.DevTeam = String.Join(",", project.DevTeamList.Where(s => !String.IsNullOrWhiteSpace(s))); foreach (var dev in SharedManager.SplitString(insertProject.DevTeam)) { //if (String.IsNullOrEmpty(dev)) continue; if (scrumMaster == dev) { return(dev + " is the Scrum Master"); } if (!UserManager.CheckExistingEmail(dev)) { return(dev + " does not exist"); } } context.Projects.Add(insertProject); context.SaveChanges(); pr = insertProject; return(""); } } catch (Exception e) { SharedManager.Log(e, "AddProject"); return(SharedManager.DatabaseError); } }
public static string ChangeItem(Sprint sprint, Item item) { if (item == null) { return("Error when adding. Please try again"); } else { using (var context = new DatabaseContext()) { using (var dbTransaction = context.Database.BeginTransaction()) { try { item = context.Items.Where(m => m.ItemID == item.ItemID).First(); item.SprintlessProjectID = 0; context.SaveChanges(); //FIXME sprintID is attributed when Add() if (sprint != null) { var number = (sprint.Items == null) ? 1 : (SharedManager.SplitString(sprint.Items)).Count() + 1; if (number == -1) { return(SharedManager.DatabaseError); } //check assignedto member of sprint item.ItemNumber = number; if (AddItemToSprint(sprint.SprintID, item.ItemID) != "") { throw new Exception(); } } dbTransaction.Commit(); return(""); } catch (Exception e) { dbTransaction.Rollback(); SharedManager.Log(e, "AddItem"); return(SharedManager.DatabaseError); } } } } }
public static List <Item> GetSprintlessItems(Project project) { try { using (var context = new DatabaseContext()) { var items = context.Items.Where(m => m.SprintlessProjectID == project.ProjectID).ToList(); return(items); } } catch (Exception e) { SharedManager.Log(e, "GetSprintlessItems"); return(new List <Item>()); } }
//if memeber exists or differnet public static string AddMember(string member, int projectID) { try { if (member == null) { return("Email cannot be null"); } using (var context = new DatabaseContext()) { var proj = (from project in context.Projects where project.ProjectID == projectID select project).First(); if (proj == null) { return("Project not found"); } if (SharedManager.SplitString(proj.DevTeam).Contains(member) || proj.ScrumMaster == member) { return("Member already exists"); } if (!UserManager.CheckExistingEmail(member)) { return(member + " does not exist"); } if (UserManager.GetUserByEmail(member).Role == "ScrumMaster") { return(member + " is a Scrum Master"); } proj.DevTeam += "," + member; context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "GetSprintFromProject"); return(SharedManager.DatabaseError); } }
public static List <Project> GetProjectsByEmail(string userEmail) { try { using (var context = new DatabaseContext()) { var projects = (from proj in context.Projects select proj).ToList(); return(projects.Where(m => SharedManager.SplitString(m.DevTeam).Contains(userEmail) || m.ScrumMaster == userEmail).ToList()); } } catch (Exception e) { SharedManager.Log(e, "GetProjectsByEmail"); return(new List <Project>()); } }
public static Item GetItemFromID(int itemID) { try { using (var context = new DatabaseContext()) { var itemRet = (from it in context.Items where it.ItemID == itemID select it).First(); return(itemRet); } } catch (Exception e) { SharedManager.Log(e, "GetItemFromID"); return(new Item()); } }
public static string AddMeeting(Meeting meeting, int sprintID) { if (meeting == null) { return("Error when adding. Please try again"); } else { try { meeting.SprintID = sprintID; using (var context = new DatabaseContext()) { if (!UserManager.CheckExistingEmail(meeting.ScrumMaster)) { return(meeting.ScrumMaster + " does not exist"); } if (!UserManager.CheckExistingEmail(meeting.Developer) && !meeting.Developer.Contains(",")) { return(meeting.Developer + " does not exist"); } if (meeting.Time < DateTime.Now) { return("Time for meeting invalid"); } if (meeting.Time.DayOfWeek == DayOfWeek.Saturday || meeting.Time.DayOfWeek == DayOfWeek.Sunday) { return("Not a week day"); } context.Meetings.Add(meeting); context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "AddMeeting"); return(SharedManager.DatabaseError); } } }
public static string ChangeSprintInItem(List <SprintItem> item, int projectID) { try { using (var context = new DatabaseContext()) { foreach (var i in item) { var p = (from proj in context.Projects where proj.ProjectID == projectID select proj).FirstOrDefault(); var s = (from sprint in context.Sprints where sprint.SprintName == i.Sprint && p.Sprints.Contains(sprint.SprintID + ",") select sprint).FirstOrDefault(); if (s == null) { continue; } if (!SharedManager.SplitString(s.Items).Contains(i.Item)) { var it = SprintManager.GetItemFromID(Convert.ToInt32(i.Item)); if (it.SprintlessProjectID == 0) { SprintManager.AddItem(s, it); } else { SprintManager.ChangeItem(s, it); } } } context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "ChangeSprintInItem"); return(SharedManager.DatabaseError); } }
public static void ReprioritiseItems(int id, List <Item> items) { try { using (var context = new DatabaseContext()) { var sprint = (from sp in context.Sprints where sp.SprintID == id select sp).First(); sprint.Items = String.Join(",", items.Select(m => m.ItemID).ToList()) + ","; context.SaveChanges(); } } catch (Exception e) { SharedManager.Log(e, "ReprioritiseItems"); } }
//private static int GetNewSprintNumber() //{ // try { // using (var context = new DatabaseContext()) // { // var count = context.Sprints.Count(); // if (count == 0) // return 1; // return count+1; // } // } // catch (Exception e) // { // SharedManager.Log(e, "GetSprintNumber"); // return -1; // } //} public static string AddSprintToProject(int projectID, int sprintID) { try { using (var context = new DatabaseContext()) { var proj = (from project in context.Projects where project.ProjectID == projectID select project).FirstOrDefault(); proj.Sprints += sprintID + ","; context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "AddSprintToProject"); return(SharedManager.DatabaseError); } }
public static Item Add_Notes(int itemID, string note) { try { using (var context = new DatabaseContext()) { var itemRet = (from it in context.Items where it.ItemID == itemID select it).First(); itemRet.ItemNotes += ".NOTE_SEPARATOR." + note; context.SaveChanges(); return(itemRet); } } catch (Exception e) { SharedManager.Log(e, "Add_Notes"); return(null); } }
public static LoginStatus Login(Login log) { try { using (var context = new DatabaseContext()) { var userSet = from user in context.Users select new { user.Email, user.Password, user.Role }; foreach (var record in userSet) { var result_password = Hash(log.Password); if (record.Email.Equals(log.Email) && result_password.Equals(record.Password)) { if (record.Role == "Developer" || record.Role == "ScrumMaster") { return(LoginStatus.RegularUser); } return(LoginStatus.RegularUser); } } return(LoginStatus.Fail); } } catch (Exception e) { SharedManager.Log(e, "Login"); return(LoginStatus.DBFail); } }
public static string AddSprint(Sprint sprint, Project proj) { if (sprint == null) { return("Error when adding. Please try again"); } using (var context = new DatabaseContext()) { using (var dbTransaction = context.Database.BeginTransaction()) { try { var b = (from s in context.Sprints where sprint.SprintName == s.SprintName select s).FirstOrDefault(); if (b != null) { return("A Sprint already exists with that name"); } var number = (proj.Sprints == null) ? 1 : (SharedManager.SplitString(proj.Sprints)).Count() + 1; sprint.SprintNumber = number; context.Sprints.Add(sprint); context.SaveChanges(); AddSprintToProject(proj.ProjectID, sprint.SprintID); dbTransaction.Commit(); return(""); } catch (Exception e) { dbTransaction.Rollback(); SharedManager.Log(e, "AddSprint"); return(SharedManager.DatabaseError); } } } }
public static List <Sprint> GetSprintFromProject(string sprintString) { try { if (sprintString == null) { return(new List <Sprint>()); } var sprints = SharedManager.SplitString(sprintString); using (var context = new DatabaseContext()) { var sprintList = context.Sprints.Where(m => sprints.Any(m2 => m2 == m.SprintID.ToString())).ToList(); return(sprintList); } } catch (Exception e) { SharedManager.Log(e, "GetSprintFromProject"); return(new List <Sprint>()); } }
public static string RemoveMeeting(Meeting meeting) { try { using (var context = new DatabaseContext()) { var meetingRet = (from meet in context.Meetings where (meet.MeetingID == meeting.MeetingID) select meet).First(); context.Meetings.Remove(meetingRet); context.SaveChanges(); return(""); } } catch (Exception e) { SharedManager.Log(e, "RemoveMeeting"); return(SharedManager.DatabaseError); } }