public ProjectCreateViewModel CreateProjectViewModel( bool redirected, ProjectCreateBindingModel binding = null, IEnumerable <ModelError> errors = null) { var viewModel = new ProjectCreateViewModel(); viewModel.Redirected = redirected; if (binding != null) { viewModel.ProjectId = binding.ProjectId; viewModel.Title = binding.Title; viewModel.Description = binding.Description; viewModel.AddMembers = binding.AddMembers; } if (errors != null) { viewModel.Errors = new List <string>(); foreach (var error in errors) { viewModel.Errors.Add(error.ErrorMessage); } } return(viewModel); }
public async Task <ActionResult> Create(ProjectCreateBindingModel form) { if (!ModelState.IsValid) { IEnumerable <ModelError> errors = ModelState.Values.SelectMany(v => v.Errors); var viewModel = _projectService.CreateProjectViewModel(false, form, errors); return(View(viewModel)); } await _projectService.CreateProject(form, HttpContext); return(RedirectToAction(nameof(Index))); }
public async Task <IHttpActionResult> Create(ProjectCreateBindingModel bindingModel) { Laboratory laboratory = await GetLaboratory.FindByIdAsync(bindingModel.IdLaboratory); User usuario = await GetUsers.FindByEmail(bindingModel.EmailUsuario); Project project = new Project { Titulo = bindingModel.Titulo, Descricao = bindingModel.Descricao, Laboratory = laboratory, DataCriacao = DateTime.Now, DataFinalizacao = null, }; project.Users.Add(usuario); laboratory.Adiciona(project); var atualizou = await GetLaboratory.Update(laboratory); return(Ok()); }
public async Task CreateProject(ProjectCreateBindingModel form, HttpContext request) { var project = new Project { ProjectId = form.ProjectId, CreatedDate = DateTime.Now, Title = form.Title, Description = form.Description, Creator = await _userManager.GetUserAsync(request.User), Tickets = new List <Ticket>(), Members = new List <UserProject>() }; if (!form.AddMembers.Contains(project.Creator.UserName)) // In case user still adds themselves as a member. { form.AddMembers.Add(project.Creator.UserName); } _userProjectService.AddMembersToProject(form.AddMembers, project); _context.Projects.Add(project); _context.SaveChanges(true); }