public async Task <FlatTypeMasterDTO> SaveUpdateAsync(FlatTypeMasterDTO modelDTO)
        {
            modelDTO.UpdatedDate = Converters.GetCurrentEpochTime();
            var model = Mapper.Map <FlatTypeMasterDTO, FlatTypeMaster>(modelDTO);

            if (model.FlatTypeMasterID == 0)
            {
                model.CreatedDate = modelDTO.UpdatedDate;
                model.IsActive    = true;
                await this._dbContext.FlatTypeMaster.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 <FlatTypeMaster, FlatTypeMasterDTO>(model);
            return(modelDTO);
        }
Exemple #2
0
        public async Task <object> Post([FromBody] FlatTypeMasterDTO 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);
        }