public Result Edit(int id, GeneralSettingEditAdminDto dto)
        {
            dto.Id = id;
            var result = _validatorEdit.ValidateResult(dto);

            if (!result.Success)
            {
                return(result);
            }

            if (dto.Id > 0)
            {
                var entity = _GeneralSettingRepository.AsNoTracking.FirstOrDefault(w => w.Id == dto.Id);

                if (entity == null)
                {
                    return(result.SetError("There are error for update record. Please try again with refresh."));
                }

                Mapper.Map <GeneralSetting>(dto, entity);
                _GeneralSettingRepository.Update(entity);
                _unitOfWork.Commit();

                result.Id = entity.Id;
            }
            else
            {
                var entity = Mapper.Map <GeneralSetting>(dto);
                _GeneralSettingRepository.Insert(entity);
                _unitOfWork.Commit();

                result.Id = entity.Id;
            }

            GeneralSettingCacheManager.ClearCache();

            return(result.SetSuccess(Messages.RecordSaved));
        }
Ejemplo n.º 2
0
 // [AuthorizeApiAdminUser(permissions: new [] {"GeneralSettings.Edit"})]
 public IHttpActionResult Put(int id, [FromBody] GeneralSettingEditAdminDto dto)
 {
     return(Result(_GeneralSettingRepository.Edit(id, dto)));
 }