public ServiceResponseDTO <PrimarySkillDTO> Put([FromBody] PrimarySkillDTO value) { var response = new ServiceResponseDTO <PrimarySkillDTO>(); try { if (value.Id != 0) { response = _primarySkillService.UpdatePrimarySkill(value); } else { response.Errors.Add("Id not present."); } } catch (Exception ex) { response.Errors = new List <string>() { ex.Message }; response.Success = false; } return(response); }
public ObjectResult Post([FromBody] PrimarySkillDTO value) { try { var primarySkill = _primarySkillService.AddPrimarySkill(value); return(new OkObjectResult(primarySkill.ResponseData)); } catch (Exception ex) { return(new BadRequestObjectResult(ex)); } }
/// <summary> /// /// </summary> /// <param name="primarySkill"></param> /// <returns></returns> public PrimarySkillDTO UpdatePrimarySkill(PrimarySkillDTO primarySkill) { var _primarySkill = _dbContext.PrimarySkill.Where(r => r.Id == primarySkill.Id).First(); _primarySkill.Name = primarySkill.Name; _primarySkill.Description = primarySkill.Description; _primarySkill.IsActive = primarySkill.IsActive; _primarySkill.DateUpdated = DateTime.Now; _dbContext.PrimarySkill.Update(_primarySkill); _dbContext.SaveChanges(); return(primarySkill); }
public PrimarySkillDTO ConvertToDTO(PrimarySkill model) { PrimarySkillDTO dto = new PrimarySkillDTO() { IsActive = model.IsActive, Description = model.Description, Id = model.Id, Name = model.Name, DateCreated = model.DateCreated, DateUpdated = model.DateUpdated ?? DateTime.Now }; return(dto); }
public PrimarySkill ConvertToModel(PrimarySkillDTO dto) { PrimarySkill model = new PrimarySkill() { Name = dto.Name, Description = dto.Description, Id = dto.Id, IsActive = dto.IsActive, DateCreated = dto.DateCreated, DateUpdated = dto.DateUpdated }; return(model); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public PrimarySkillDTO GetPrimarySkill(int id) { PrimarySkillDTO dto = new PrimarySkillDTO(); try { var primarySkill = _dbContext.PrimarySkill.FirstOrDefault(a => a.Id == id); if (primarySkill != null) { dto = ConvertToDTO(primarySkill); } } catch (Exception) { // logging throw; } return(dto); }
public ServiceResponseDTO <PrimarySkillDTO> UpdatePrimarySkill(PrimarySkillDTO primarySkill) { var result = new ServiceResponseDTO <PrimarySkillDTO>(); try { result.ResponseData = _primarySkillRepository.UpdatePrimarySkill(primarySkill); result.Success = true; } catch (Exception ex) { result.Errors = new List <string>() { ex.Message }; result.Success = false; } return(result); }
/// <summary> /// Creates new primaryskill /// </summary> /// <param name="newPrimarySkill"></param> /// <returns></returns> public ServiceResponseDTO <PrimarySkillDTO> AddPrimarySkill(PrimarySkillDTO newPrimarySkill) { ServiceResponseDTO <PrimarySkillDTO> result = new ServiceResponseDTO <PrimarySkillDTO>(); PrimarySkillDTO primarySkill; try { primarySkill = _primarySkillRepository.AddPrimarySkill(newPrimarySkill); result.ResponseData = primarySkill; result.Success = true; } catch (Exception ex) { result.Errors = new List <string>() { ex.Message }; result.Success = false; } return(result); }
/// <summary> /// /// </summary> /// <param name="newPrimarySkill"></param> /// <returns></returns> public PrimarySkillDTO AddPrimarySkill(PrimarySkillDTO newPrimarySkill) { var primarySkill = new PrimarySkill() { Name = newPrimarySkill.Name, Description = newPrimarySkill.Description, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, }; try { _dbContext.PrimarySkill.Add(primarySkill); _dbContext.SaveChanges(); newPrimarySkill.Id = primarySkill.Id; } catch (Exception ex) { throw ex; } return(newPrimarySkill); }