public async Task <IHttpActionResult> CreateAsync(LaboratoryBindingModel bindingModel) { User oldUser = await GetUsers.FindByEmail(bindingModel.EmailUsuario); Laboratory laboratory = new Laboratory() { Descricao = bindingModel.Descricao, }; laboratory.Adiciona(oldUser); oldUser.Adiciona(laboratory); var criouLab = await GetLaboratory.Create(laboratory); if (!oldUser.haveRole()) { Role coordenador = new Role() { Id = 2, Descricao = "COORDENADOR" }; oldUser.Role = coordenador; } var atualizado = GetUsers.UpdateEF2(oldUser); if (!criouLab || !atualizado) { return(BadRequest("Erro interno")); } return(Ok()); }
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()); }