示例#1
0
        private async Task RemoveFilesForMessageAsync(IEnumerable <int> fileIds, int workspaceId)
        {
            var files = await _context.Files
                        .Include(f => f.MessageFileAttachments)
                        .Where(f => fileIds.Contains(f.Id)).ToListAsync();

            foreach (var file in files)
            {
                if (file.MessageFileAttachments.Any())
                {
                    continue;
                }

                _context.Files.Remove(file);
                await _context.SaveChangesAsync();

                await _fileHelper.DeleteFileAsync(file.SavedName, workspaceId);
            }
        }
示例#2
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);
        }
示例#3
0
        public async Task <TariffDto> Update(TariffCreateOrUpdateDto input)
        {
            if (!input.IsUpdateEntry())
            {
                throw new NoNullAllowedException("item does not exist or could not be found");
            }

            //var existingItems = UnitOfWork.TariffItemRepository.GetAllWithTariffId(input.Id.Value);
            var newItems = input.TariffItems.MapTo <List <TariffItem> >();
            var tariffEntityFromDatabase = await UnitOfWork.TariffRepository.GetByIdAsync(input.Id);

            var tariff = input.MapTo <Eron.Core.Entities.Financial.Order.Tariff>();

            #region Handle Items

            ////delete old items which do not exist any more
            //foreach (var item in existingItems.Where(x => !newItems.Contains(x)))
            //{
            //    UnitOfWork.TariffItemRepository.Delete(item);
            //}

            ////add new Items which did not exist before
            //foreach (var item in newItems.Where(x => !existingItems.Contains(x)))
            //{
            //    item.TariffId = input.Id.Value;
            //    UnitOfWork.TariffItemRepository.Create(item);
            //}

            #endregion

            #region Handle Price

            //fetch existing valid price
            var existingPrice = UnitOfWork.TariffPriceRepository.GetValidByTariffId(input.Id.Value);
            //check if current price is up to date
            var newPrice = new Eron.Core.Entities.Financial.Order.TariffPrice();
            if (existingPrice.Price != input.TariffPrice)
            {
                existingPrice.IsValid = false;

                //update old tariff price
                UnitOfWork.TariffPriceRepository.Update(existingPrice);

                //create new tariff price
                newPrice = new Eron.Core.Entities.Financial.Order.TariffPrice().Create(input.TariffPrice, input.Id.Value);
                newPrice = UnitOfWork.TariffPriceRepository.Create(newPrice);
                await UnitOfWork.SaveAsync();
            }

            #endregion

            #region Handle Images

            if (tariff.ImageId.HasValue && tariff.ImageId != tariffEntityFromDatabase.ImageId)
            {
                var newImage = await _fileHelper.GetFileAsync(tariff.ImageId.Value);

                if (tariffEntityFromDatabase.ImageId.HasValue)
                {
                    await _fileHelper.DeleteFileAsync(tariffEntityFromDatabase.ImageId.Value);
                }
                await _fileHelper.TransferToDatabaseAsync(newImage);
            }

            #endregion

            var tariffPriceList = UnitOfWork.TariffPriceRepository.GetAllWithTariffId(tariff.Id);

            tariff.TariffPrices = tariffPriceList;
            Mapper.Map(tariff, tariffEntityFromDatabase);

            UnitOfWork.TariffRepository.Update(tariffEntityFromDatabase);

            await UnitOfWork.SaveAsync();

            return(input.MapTo <TariffDto>());
        }
示例#4
0
 public static Task DeleteFileAsync(string filename)
 {
     return(fileHelper.DeleteFileAsync(filename));
 }