public async Task <DesignationTypeDTO> SaveUpdateAsync(DesignationTypeDTO modelDTO) { modelDTO.UpdatedDate = Converters.GetCurrentEpochTime(); var model = Mapper.Map <DesignationTypeDTO, DesignationType>(modelDTO); if (model.DesignationTypeID == 0) { model.CreatedDate = modelDTO.UpdatedDate; model.IsActive = true; await this._dbContext.DesignationType.AddAsync(model); await this._dbContext.SaveChangesAsync(); this.DisplayMessage = CommonMethods.GetMessage(this.logType, LogAction.Add); } else { this._dbContext.Entry(model).State = EntityState.Modified; await this._dbContext.SaveChangesAsync(); this.DisplayMessage = CommonMethods.GetMessage(this.logType, LogAction.Update); } modelDTO = Mapper.Map <DesignationType, DesignationTypeDTO>(model); return(modelDTO); }
public async Task <object> Post([FromBody] DesignationTypeDTO model) { try { var data = await repository.SaveUpdateAsync(model); _response.Result = data; _response.IsSuccess = repository.IsSuccess; _response.ErrorMessages = repository.ErrorMessages; _response.DisplayMessage = repository.DisplayMessage; } catch (Exception ex) { _response.IsSuccess = false; _response.ErrorMessages = new List <ErrorMessageDTO>() { new ErrorMessageDTO() { Message = ex.ToString() } }; } return(_response); }