public async Task <IActionResult> OnGetAsync() { if (Id.HasValue) { var dictionary = await dictionaryService.GetDictionaryByIdAsync(Id.Value).ConfigureAwait(false); if (dictionary == null) { return(NotFound()); } ViewModel = new CreateOrUpdateDictionaryDto { DictionaryTypeId = dictionary.DictionaryTypeId, Code = dictionary.Code, Enabled = dictionary.Enabled, Id = dictionary.Id, Remark = dictionary.Remark, Value = dictionary.Value }; } else { ViewModel = new CreateOrUpdateDictionaryDto { Enabled = true }; } return(Page()); }
public async Task <DictionaryDto> Update(Guid id, CreateOrUpdateDictionaryDto input) { var dic = await _repository.GetAsync(id); dic.Name = input.Name; dic.Description = input.Description; return(ObjectMapper.Map <DataDictionary, DictionaryDto>(dic)); }
public async Task <DictionaryDto> Create(CreateOrUpdateDictionaryDto input) { var exist = await _repository.FirstOrDefaultAsync(_ => _.Name == input.Name); if (exist != null) { throw new BusinessException("名称:" + input.Name + "字典已存在"); } var dic = new DataDictionary( GuidGenerator.Create(), input.Name, input.Description); var result = await _repository.InsertAsync(dic); return(ObjectMapper.Map <DataDictionary, DictionaryDto>(result)); }
/// <summary> /// 创建或者更新字典 /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <DataResult <long> > CreateOrUpdateDictionaryAsync(CreateOrUpdateDictionaryDto dto) { if (dto is null) { throw new ArgumentNullException(nameof(dto)); } var existType = await applicationDbContext.DictionaryTypes.AnyAsync(e => e.Id == dto.DictionaryTypeId).ConfigureAwait(false); if (!existType) { return(FailedDataResult <long>("类型不存在")); } if (dto.Id.HasValue) { var dictionary = await applicationDbContext.Dictionaries.FirstOrDefaultAsync(e => e.Id == dto.Id).ConfigureAwait(false); if (dictionary == null) { return(FailedDataResult <long>("数据字典不存在")); } dictionary = mapper.Map(dto, dictionary); } else { dto.Id = GuidEx.NewGuid(); Dictionary entity = mapper.Map <Dictionary>(dto); await applicationDbContext.Dictionaries.AddAsync(entity).ConfigureAwait(false); } try { await applicationDbContext.SaveChangesAsync().ConfigureAwait(false); return(OkDataResult(dto.Id.Value)); } catch (DbUpdateException ex) { return(FailedDataResult <long>(ex)); } }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(CreateOrUpdateDictionaryDto ViewModel) { if (ViewModel is null) { throw new ArgumentNullException(nameof(ViewModel)); } if (!TryValidateModel(ViewModel)) { return(BadRequest(ModelState)); } var result = await dictionaryService.CreateOrUpdateDictionaryAsync(ViewModel).ConfigureAwait(false); if (result.Succeeded) { return(new OkResult()); } ModelState.AddModelError(string.Empty, result.ErrorMessage); return(BadRequest(ModelState)); }
public Task <DictionaryDto> Update(Guid id, CreateOrUpdateDictionaryDto input) { return(_dictionaryAppService.Update(id, input)); }
public Task <DictionaryDto> Create(CreateOrUpdateDictionaryDto input) { return(_dictionaryAppService.Create(input)); }
public Task <DictionaryDto> Update(Guid id, CreateOrUpdateDictionaryDto input) { throw new NotImplementedException(); }