public async Task <IActionResult> AffichageExperience(Experience model, IFormFile FileP, string details, int activiteId) { model.Activites = (IList <Activite>)ActiviteService.GetActivite(model.ExperienceId); if (activiteId != 0) { string uniqueFileName = null; if (FileP != 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 and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + FileP.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder FileP.CopyTo(new FileStream(filePath, FileMode.Create)); } System.Diagnostics.Debug.WriteLine("l'id ta3 l'activité est " + activiteId); Activite a = await ActiviteService.GetActiviteById(activiteId); if (details != null) { a.Details = details; } if (uniqueFileName != null) { a.Image = uniqueFileName; } await ActiviteService.Update(a); if (details is null && uniqueFileName is null) { await ActiviteService.Update(a); } } TempData["ListeActivite"] = JsonConvert.SerializeObject(ActiviteService.GetActivite(model.ExperienceId)); TempData["experience1"] = JsonConvert.SerializeObject(model); await ExperienceService.PutExperienceAsync(model.ExperienceId, model); return(RedirectToAction("AffichageExperience", "Experience")); }
public async Task <ActionResult <string> > GetActivityById([FromRoute] string id) { Guid _id = Guid.Parse(id); BaseResponseDto <ActiviteDto> getResponse = await _activiteService.GetActiviteById(_id); if (!getResponse.HasError || getResponse.Data != null) { return(Ok(getResponse.Data)); } else if (!getResponse.HasError || getResponse.Data == null) { return(NotFound()); } else { return(BadRequest(getResponse.Errors)); } }