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); }
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); }