public async Task Update(CreateEstimateDto input) { var estimateInDB = await _estimateRepository.GetAsync(input.Id); ObjectMapper.Map(input, estimateInDB); await _estimateRepository.UpdateAsync(estimateInDB); }
public async Task Create(CreateEstimateDto input) { try { var estimate = ObjectMapper.Map <Models.Estimates>(input); var estimatesId = await _estimateRepository.InsertAndGetIdAsync(estimate); //image if (input.ListFileName.Count > 0) { foreach (var item in input.ListFileName) { var image = ObjectMapper.Map <Models.Images>(item); if (item.ImageName != null) { //Delete old document file AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.AttachmentsFolder, item.ImageUrl); var sourceFile = Path.Combine(_appFolders.TempFileDownloadFolder, item.ImageUrl); var destFile = Path.Combine(_appFolders.AttachmentsFolder, item.ImageUrl); System.IO.File.Move(sourceFile, destFile); var filePath = Path.Combine(_appFolders.AttachmentsFolder, item.ImageUrl); image.ImageUrl = filePath; image.ImageName = item.ImageName; image.ImageSize = item.ImageSize; image.EstimatesId = estimatesId; await _imageRepository.InsertAsync(image); } } await CurrentUnitOfWork.SaveChangesAsync(); } } catch (Exception e) { throw e; } }
public async Task Edit(CreateEstimateDto input) { var estimate = await _estimateRepository.FirstOrDefaultAsync(input.Id); ObjectMapper.Map(input, estimate); }