public async Task Edit(MedicineEditModel medicineEditModel) { Medicine medicine = new Medicine() { Id = medicineEditModel.Id, Name = medicineEditModel.Name, Prospect = medicineEditModel.Prospect }; _repository.Edit(medicine); if (medicineEditModel.File != null) { foreach (var file in medicineEditModel.File) { if (file.Length > 0) { var path = Path.Combine(_env.WebRootPath, "Medicines/" + medicine.Id); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (var fileStream = new FileStream(Path.Combine(path, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } } } } }
public async Task <IActionResult> Put(MedicineForEditDTO model) { Medicine medicine = mapper.Map <Medicine>(model); medicineRepository.Edit(medicine); await unitOfWork.CompleteAsync().ConfigureAwait(true); return(Ok(mapper.Map <MedicineForGetDTO>(await medicineRepository.Get(medicine.Id).ConfigureAwait(true)))); }