Example #1
0
        public ActionResult Edit(int id, ActiviteVM p, HttpPostedFileBase Affiche)
        {
            try
            {
                Activite pm = activiteService.GetById((int)id);


                pm.Title       = p.Title;
                pm.Description = p.Description;
                pm.Affiche     = Affiche.FileName;
                pm.Theme       = p.Theme;
                pm.Outils      = p.Outils;
                pm.AgeMin      = p.AgeMin;
                pm.AgeMax      = p.AgeMax;
                pm.ClassSize   = p.ClassSize;
                pm.Duration    = p.Duration;
                pm.Professor   = p.Professor;
                pm.Start       = p.Start;
                pm.Location    = p.Location;
                //    nomuser = User.Identity.GetUserName(),
                pm.UserId = "f43c21cf-f35a-4897-a9e3-343c00afe7b3";

                activiteService.Update(pm);
                activiteService.Commit();

                var path = Path.Combine(Server.MapPath("~/Content/Uploads"), Affiche.FileName);
                Affiche.SaveAs(path);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(p));
            }
        }
        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"));
        }