public async Task <RecursoHumanoDTO> Update(UsuarioDTO loggedUser, int id, RecursoHumanoDTO dto) { var entity = _mapper.Map <RecursoHumano>(dto); if (entity.IdEmpresa == loggedUser.IdEmpresa) { entity.UpdateDate = DateTime.Now; entity.UpdateUserId = loggedUser.Id; var original = await _recursoHumanoRepository.GetById(id); entity.CreationDate = original.CreationDate; entity.CreationUserId = original.CreationUserId; entity.Active = original.Active; try { entity = await _recursoHumanoRepository.Update(id, entity); } catch (Exception e) { Console.WriteLine(e.Message); } return(_mapper.Map <RecursoHumanoDTO>(entity)); } else { return(null); } }
public async Task <RecursoHumanoDTO> Create(UsuarioDTO userLogged, RecursoHumanoDTO dto) { RecursoDTO recurso = new RecursoDTO { Descripcion = "rrhh", IdEmpresa = dto.IdEmpresa, CreationUserId = userLogged.Id, IdTipoRecurso = TipoRecursoEnum.Recurso_Humano.ToInt() }; recurso = await _recursoService.Create(recurso); var entity = _mapper.Map <RecursoHumano>(dto); entity.Active = true; entity.CreationDate = DateTime.Now; entity.CreationUserId = userLogged.Id; entity.UpdateDate = DateTime.Now; entity.UpdateUserId = userLogged.Id; entity.IdEmpresa = userLogged.IdEmpresa; entity.IdRecurso = (int)recurso.Id; entity = await _recursoHumanoRepository.Insert(entity); dto = _mapper.Map <RecursoHumanoDTO>(entity); return(dto); }
public async Task <IActionResult> Update(int id, RecursoHumanoDTO entity) { try { if (ModelState.IsValid) { entity = await _recursoHumanoService.Update(this.Usuario, id, entity); return(Ok(entity)); } else { return(BadRequest(ModelState)); } } catch (Exception e) { return(StatusCode(500, e)); } }