Exemple #1
0
        public async Task <TariffCategoryDto> Update(TariffCategoryCreateOrUpdateDto input)
        {
            var entity = input.MapTo <Eron.Core.Entities.Financial.Order.TariffCategory>();

            if (input.ImageId.HasValue && input.ImageId != entity.ImageId)
            {
                if (entity.ImageId.HasValue)
                {
                    await _fileHelper.DeleteFileAsync(entity.ImageId.Value);
                }
                var newFile = await _fileHelper.GetFileAsync(input.ImageId.Value);

                await _fileHelper.TransferToDatabaseAsync(newFile);
            }
            UnitOfWork.TariffCategoryRepository.Update(entity);
            await UnitOfWork.SaveAsync();

            var result = entity.MapTo <TariffCategoryDto>();

            return(result);
        }
Exemple #2
0
        public async Task <TariffCategoryDto> Create(TariffCategoryCreateOrUpdateDto input)
        {
            if (input.ImageId != null)
            {
                var eronFile = await _fileHelper.GetFileAsync(input.ImageId.Value);

                await _fileHelper.TransferToDatabaseAsync(eronFile);
            }

            var entityFromDatabase = await UnitOfWork.TariffCategoryRepository.GetByIdAsync(input.Id);

            var entity = input.MapTo <Eron.Core.Entities.Financial.Order.TariffCategory>();

            entity.Slug = entity.Slug.Slugify();
            Mapper.Map(entity, entityFromDatabase);

            entity = UnitOfWork.TariffCategoryRepository.Create(entityFromDatabase);
            await UnitOfWork.SaveAsync();

            var result = entity.MapTo <TariffCategoryDto>();

            return(result);
        }
Exemple #3
0
        public async Task <IHttpActionResult> Put(TariffCategoryCreateOrUpdateDto input)
        {
            var result = await _service.Update(input);

            return(Ok(result));
        }