Пример #1
0
        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());
        }
Пример #2
0
        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);
        }
Пример #3
0
 public Task UpdateVoucherPlatformAsync(VoucherPlatform voucherPlatform)
 {
     return(_repository.UpdateAsync(voucherPlatform));
 }
Пример #4
0
 public Task CreateAsync(VoucherPlatform voucherPlatform)
 {
     return(_repository.InsertAsync(voucherPlatform));
 }