Пример #1
0
        public ActionResult ValidateSubmission(InitiatedProjectViewModel project, string resubmit)
        {
            Student student = _studentctx.GetStudent(User.Identity.Name);
            int?    groupId = student.group_id;

            if (project.Submit != "Submit")
            {
                ModelState.Clear();
                if (string.IsNullOrEmpty(project.Title))
                {
                    ModelState.AddModelError("", "Enter the proposal title to save");
                }
                else
                {
                    if (project.displayFields != null)
                    {
                        var model = JsonConvert.DeserializeObject <List <ViewModels.InitiatedProject.Field> >(project.displayFields);
                        foreach (ViewModels.InitiatedProject.Field f in model)
                        {
                            if (f.value.Length > 500)
                            {
                                ModelState.AddModelError("", "One of the fields '" + f.label + "' has exceeded maximum of 500 characters");
                                project.displayFieldsModel = model;
                                return(View("_Create", project));
                            }
                        }
                    }
                    project.SavedDate = DateTime.Now;
                    _projectctx.AddSelfInitiatedProject(project, (int)groupId, student.course_id);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                if (project.displayFields != null)
                {
                    var model = JsonConvert.DeserializeObject <List <ViewModels.InitiatedProject.Field> >(project.displayFields);
                    foreach (ViewModels.InitiatedProject.Field f in model)
                    {
                        if (f.value.Length > 500)
                        {
                            ModelState.AddModelError("", "One of the fields '" + f.label + "' has exceeded maximum of 500 characters");
                            return(View("_Create", project));
                        }
                    }
                }
                switch (resubmit)
                {
                case "":
                    if (ModelState.IsValid)
                    {
                        if (_projectctx.GetProjectByGroup((int)student.group_id) == null)
                        {
                            project.SubmittedDate = DateTime.Now;
                            _projectctx.AddSelfInitiatedProject(project, (int)groupId, student.course_id);
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    break;

                case "resubmit":
                    project.SubmittedDate = DateTime.Now;
                    _projectctx.AddProjectHistory(_projectctx.GetProjectByGroup((int)student.group_id).Id);
                    _projectctx.AddSelfInitiatedProject(project, (int)groupId, student.course_id);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View("_Create"));
        }