public IActionResult SubDepartmentGalary(int id, IFormFile file) // IFormFile for one Photo and IFormCollection for Multi Photo { var subDepartment = subDepartmentRepo.GetById(id); if (subDepartment == null) { return(NotFound()); } var uploadFolderPath = Path.Combine(host.WebRootPath, "galary"); if (!Directory.Exists(uploadFolderPath)) { Directory.CreateDirectory(uploadFolderPath); } var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); var filePath = Path.Combine(uploadFolderPath, fileName); using (var stream = new FileStream(filePath, FileMode.Create)) { file.CopyTo(stream); } var photo = new GalaryModel { FileName = fileName }; // subDepartment.Photos.Add(photo); photo.SubDepartmentId = subDepartment.Id; galaryRepo.Add(photo); uow.Save(); var result = mapper.Map <GalaryModel, GalaryResource>(photo); return(Ok(result)); }
public void Delete(GalaryModel photo) { context.Galary.Remove(photo); }
public void Add(GalaryModel galary) { context.Add(galary); }