Beispiel #1
0
        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"));
        }
Beispiel #2
0
        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");
        }