public async Task <FlatMasterDTO> SaveUpdateAsync(FlatMasterDTO modelDTO) { modelDTO.UpdatedDate = Converters.GetCurrentEpochTime(); var model = Mapper.Map <FlatMasterDTO, FlatMaster>(modelDTO); if (model.FlatMasterID == 0) { model.CreatedDate = modelDTO.UpdatedDate; model.IsActive = true; await this._dbContext.FlatMaster.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 <FlatMaster, FlatMasterDTO>(model); return(modelDTO); }
public async Task <object> Post([FromBody] FlatMasterDTO 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); }