public async Task <EntityDto> CreateOrUpdateVoucherPlatform(VoucherPlatformEditDto input) { try { var isEdit = input.Id > 0; VoucherPlatform platform; if (isEdit) { platform = await _voucherPlatformManager.FindAsync(input.Id); if (platform == null) { throw new UserFriendlyException(L("InvalidVoucherPlatform")); } } else { platform = new VoucherPlatform(input.Name); } platform.UpdateName(input.Name); platform.UpdateSettings(input.TermConditionJson); if (!isEdit) { await _voucherPlatformManager.CreateAsync(platform); } else { await _voucherPlatformManager.UpdateVoucherPlatformAsync(platform); } await CurrentUnitOfWork.SaveChangesAsync(); return(new EntityDto(platform.Id)); } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } return(new EntityDto()); }
public async Task <VoucherPlatformEditDto> GetVoucherPlatformForEdit(EntityDto input) { VoucherPlatform platform; if (input.Id > 0) { platform = await _voucherPlatformManager.FindAsync(input.Id, considerArchived : true); if (platform == null) { throw new UserFriendlyException(L("InvalidVoucherPlatform")); } } else { platform = new VoucherPlatform("New Voucher Platform"); } var dto = ObjectMapper.Map <VoucherPlatformEditDto>(platform); dto.TermConditionJson = platform.GetSettings(); return(dto); }
public Task UpdateVoucherPlatformAsync(VoucherPlatform voucherPlatform) { return(_repository.UpdateAsync(voucherPlatform)); }
public Task CreateAsync(VoucherPlatform voucherPlatform) { return(_repository.InsertAsync(voucherPlatform)); }