public async Task <IActionResult> AddLogement(LogementExtViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; List <LNDocuments> emp = new List <LNDocuments>(); if (model.FileP != null && model.FileP.Count > 0) { // Loop thru each selected file foreach (IFormFile photo in model.FileP) { LNDocuments employe = new LNDocuments(); // The file must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the injected // IHostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Files"); // To make sure the file name is unique we are appending a new // GUID value and and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder photo.CopyTo(new FileStream(filePath, FileMode.Create)); employe.Filepath = uniqueFileName; emp.Add(employe); } } Fournisseur f = (Fournisseur)userManager.GetUserAsync(User).Result; ServiceLogment serviceLogment = new ServiceLogment { Adresse = model.Adresse, Description = model.Description, PrixParNuit = model.PrixParNuit, Titre = model.Titre, Category = model.Category , Type = model.Type, Fournisseur = f, Documents = emp }; await logementService.Ajout(serviceLogment); TempData["id"] = JsonConvert.SerializeObject(serviceLogment.Id); return(RedirectToAction("DetailsLogement", "Service")); } return(View(model)); }
public IActionResult DetailsLogement(int id) { if (id == 0) { ViewData["id"] = JsonConvert.DeserializeObject <int>((string)TempData["id"]); TempData.Keep("id"); id = (int)ViewData["id"]; } ViewBag.user = userManager.GetUserAsync(User).Result; // ViewBag.Best = ExperienceService.BestExperience(); ServiceLogment logment = logementService.GetById(id).Result; return(View(logment)); }
public Task Update(ServiceLogment logement) { return(GenericRepo.PutAsync(logement.Id, logement)); }
public async Task <ServiceLogment> GetById(int id) { ServiceLogment l = await LogementRepo.GetlogementDetailsAsync(id); return(l); }
public Task Delete(ServiceLogment logement) { return(GenericRepo.DeleteAsync(logement.Id)); }
public Task Ajout(ServiceLogment logement) { return(GenericRepo.InsertAsync(logement)); }