public ActionResult Create(CreateViewModel model) { ViewBag.CategorieID = new SelectList(categorieRepository.GetAll(), "CategorieId", "CategorieName"); if (ModelState.IsValid) { string uniqueFileName = null; // If the Photo property on the incoming model object is not null, then the user // has selected an image to upload. if (model.Photo != null) { // The image must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the inject // HostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); // To make sure the file name is unique we are appending a new // GUID value and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } Certification newCertification = new Certification { CertificationName = model.CertificationName, Description = model.Description, Price = model.Price, CategorieId = model.CategorieId, Categorie = model.Categorie, // Store the file name in PhotoPath property of the certification object // which gets saved to the Certifications database table PhotoPath = uniqueFileName }; certificationRepository.Add(newCertification); return(RedirectToAction("details", new { id = newCertification.CertificationId })); } return(View()); }
public int AddCertification(DLModel.Certification _certification) { return(_certificationRepository.Add((DLModel.Certification) new DLModel.Certification().InjectFrom(_certification)).CertificationID); }
public void AddCertificate(CertificationDto entity) { repo.Add(entity); }