internal void AddGroupsToProject(System.IO.Stream stream, Project insertProject) { BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext(); using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(stream, false)) { WorkbookPart workBookPart = spreadsheetDocument.WorkbookPart; foreach (Sheet s in workBookPart.Workbook.Descendants <Sheet>()) { WorksheetPart wsPart = workBookPart.GetPartById(s.Id) as WorksheetPart; System.Diagnostics.Debug.WriteLine("Worksheet {1}:{2} - id({0}) {3}", s.Id, s.SheetId, s.Name, wsPart == null ? "NOT FOUND!" : "found."); if (wsPart == null) { continue; } Row[] rows = wsPart.Worksheet.Descendants <Row>().ToArray(); List <string> groupsToAdd = new List <string>(); //assumes the first row contains column names foreach (Row row in wsPart.Worksheet.Descendants <Row>()) { bool emptyRow = true; string[] values = row.ElementAt(4).ToString().Split(','); emptyRow = emptyRow && (values.Count() > 0); foreach (string value in values) { if (!groupsToAdd.Contains(value)) { groupsToAdd.Add(value); } } } foreach (string projectgroup in groupsToAdd) { var groupResult = from pg in context.ProjectGroups where pg.group_code == projectgroup select pg; BarometerDataAccesLayer.ProjectGroup group = groupResult.First(); group.Project = insertProject; } } } }
public ActionResult DeleteProject(int projectId) { BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext(); var resultProjects = from p in context.Projects where p.id == projectId select p; context.Projects.DeleteOnSubmit(resultProjects.First()); context.SubmitChanges(); return(RedirectToAction("List")); }
public ActionResult StudentForm(FormCollection collection) { int studentNumber = int.Parse(collection.GetValue("student").AttemptedValue); //UserDashboardWrapper userwrap = new UserDashboardWrapper(studentNumber); BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext(); var student = from u in context.Users where u.student_number == studentNumber select u.id; int studentId = student.First(); return(RedirectToAction("Dashboard", "User", new { studentId = studentNumber })); }
public ActionResult Create(FormCollection collection) { if (collection.Count != 0) { BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext(); BarometerDataAccesLayer.Project insertProject = new BarometerDataAccesLayer.Project(); BarometerDataAccesLayer.ProjectOwner me = new BarometerDataAccesLayer.ProjectOwner(); var ownerInfo = from u in context.Users where u.student_number == CurrentUser.getInstance().Studentnummer select u; me.User = ownerInfo.First(); insertProject.name = collection.GetValue("FormProject.name").AttemptedValue; insertProject.description = collection.GetValue("FormProject.description").AttemptedValue; insertProject.start_date = DateTime.ParseExact(collection.GetValue("FormProject.start_date").AttemptedValue, "dd-MM-yyyy", CultureInfo.InvariantCulture); insertProject.end_date = DateTime.ParseExact(collection.GetValue("FormProject.end_date").AttemptedValue, "dd-MM-yyyy", CultureInfo.InvariantCulture); insertProject.ProjectOwners.Add(me); insertProject.status_name = "Pending"; if (Request.Files.Count != 0) { HttpPostedFileBase fileBase = Request.Files[0]; StudentExcel studentExcel = new StudentExcel(insertProject); studentExcel.Import(fileBase.InputStream); insertProject.baro_template_id = int.Parse(collection.GetValue("FormProject.baro_template_id").AttemptedValue); string[] reportDateNames = collection.GetValue("reportDateName[]").AttemptedValue.Split(','); string[] reportStartDates = collection.GetValue("reportStartDate[]").AttemptedValue.Split(','); string[] reportEndDates = collection.GetValue("reportEndDate[]").AttemptedValue.Split(','); EntitySet <BarometerDataAccesLayer.ProjectReportDate> reportDateEntities = new EntitySet <BarometerDataAccesLayer.ProjectReportDate>(); int counter = 0; foreach (string reportDateName in reportDateNames) { BarometerDataAccesLayer.ProjectReportDate tmpReportDate = new BarometerDataAccesLayer.ProjectReportDate(); tmpReportDate.Project = insertProject; tmpReportDate.week_label = reportDateName; tmpReportDate.start_date = DateTime.Parse(reportStartDates[counter]); tmpReportDate.end_date = DateTime.Parse(reportEndDates[counter]); context.ProjectReportDates.InsertOnSubmit(tmpReportDate); counter++; } context.SubmitChanges(); } } return(RedirectToAction("List")); }
public ActionResult Student(int studentId) { BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext(); var student = from u in context.Users where u.id == studentId select u; if (student.ToList().Count > 0) { return(View(student.First())); } else { throw new DataException("No data found"); } }
public ActionResult AddStudent(FormCollection collection) { int studentIdToAdd = int.Parse(collection.GetValue("student").AttemptedValue); int projectId = int.Parse(collection.GetValue("projectID").AttemptedValue); int groupId = int.Parse(collection.GetValue("groupID").AttemptedValue); DAOStudent studentdao = DatabaseFactory.getInstance().getDAOStudent(); DAOProject projectdao = DatabaseFactory.getInstance().getDAOProject(); BarometerDataAccesLayer.User studentUser = studentdao.getStudentInfo(studentIdToAdd); IEnumerable <BarometerDataAccesLayer.ProjectMember> member = studentUser.ProjectMembers.Where(pm => pm.project_group_id == groupId); if (member.Count() == 0) { BarometerDataAccesLayer.ProjectMember pMember = new BarometerDataAccesLayer.ProjectMember(); pMember.User = studentUser; pMember.project_group_id = groupId; BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext(); context.ProjectMembers.InsertOnSubmit(pMember); context.SubmitChanges(); } return(RedirectToAction("ProjectGroups", new { groupId = groupId })); }
private void FillDatabase(Dictionary <int, object[]> rowData, Project insertProject) { BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext(); foreach (KeyValuePair <int, object[]> cell in rowData) { bool userExists = false; if (cell.Key != 0 && cell.Value[0].ToString() != "") { int studentNumber = int.Parse(cell.Value[0].ToString()); BarometerDataAccesLayer.User insertUser = null; var existingUser = from u in context.Users where u.student_number == studentNumber select u; int test = 0; if (!existingUser.Any()) { //If doesnt exist, create empty one insertUser = new BarometerDataAccesLayer.User(); } else { //If exists, get user userExists = true; insertUser = existingUser.First(); } insertUser.student_number = int.Parse(cell.Value[0].ToString()); insertUser.firstname = cell.Value[1].ToString(); insertUser.lastname = cell.Value[2].ToString(); insertUser.email = cell.Value[3].ToString(); if (cell.Value[4].ToString() != "") { string[] groups = cell.Value[4].ToString().Split(','); foreach (string groupcode in groups) { bool groupExists = false; var currentGroup = from pg in context.ProjectGroups where pg.group_code == groupcode select pg; ProjectGroup newGroup = null; if (currentGroup.Count() == 0) { //Groep bestaat nog niet, aanmaken newGroup = new ProjectGroup(); newGroup.group_code = groupcode; } else { groupExists = true; newGroup = currentGroup.First(); } if (insertProject != null) { newGroup.Project = insertProject; } ProjectMember member = new ProjectMember(); member.student_user_id = insertUser.id; member.ProjectGroup = newGroup; if (!groupExists) { context.ProjectGroups.InsertOnSubmit(newGroup); } context.ProjectMembers.InsertOnSubmit(member); } } if (!userExists) { context.Users.InsertOnSubmit(insertUser); } } } context.SubmitChanges(); }