Ejemplo n.º 1
0
        public async Task <ProjectMasterDTO> SaveUpdateAsync(ProjectMasterDTO modelDTO)
        {
            modelDTO.CompanyMasterID = this.Request.CompanyID;
            modelDTO.UpdatedDate     = Converters.GetCurrentEpochTime();
            var model = Mapper.Map <ProjectMasterDTO, ProjectMaster>(modelDTO);

            if (model.ProjectMasterID == 0)
            {
                model.CreatedDate = modelDTO.UpdatedDate;
                model.IsActive    = true;
                await this._dbContext.ProjectMaster.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 <ProjectMaster, ProjectMasterDTO>(model);
            return(modelDTO);
        }
Ejemplo n.º 2
0
        public async Task <object> Post([FromBody] ProjectMasterDTO 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);
        }