예제 #1
0
        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));
        }
예제 #2
0
        public async Task <IActionResult> AddRestaurant(NourritureExtViewModel model)
        {
            //ViewData["Message"] = JsonConvert.DeserializeObject<List<Activite>>((string)TempData.Peek("Message"));
            //TempData.Keep("Message");
            //Activites = (ICollection<Activite>)ViewData["Message"];
            if (ModelState.IsValid)
            {
                string uniqueFileName  = null;
                string uniqueFileName2 = 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);
                    }
                }


                if (model.FilePp != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Files");

                    uniqueFileName2 = Guid.NewGuid().ToString() + "_" + model.FilePp.FileName;
                    string filePath1 = Path.Combine(uploadsFolder, uniqueFileName2);

                    model.FilePp.CopyTo(new FileStream(filePath1, FileMode.Create));
                }


                string            id         = userManager.GetUserId(User);
                ServiceNouritture nourriture = new ServiceNouritture
                {
                    FournisseurId = id,
                    TypeResto     = model.TypeResto,
                    SpecialeResto = model.SpecialeResto,
                    NomRestau     = model.NomRestau,

                    Description = model.Description,
                    Plat        = model.Plat,

                    Prix    = model.Prix,
                    Menu    = uniqueFileName2,
                    regles  = model.regles,
                    Adresse = model.Adresse,
                    Slogon  = model.Slogon
                    ,
                    Site      = model.Site,
                    Rating    = model.Rating,
                    Documents = emp,
                };



                await nourritureService.Ajout(nourriture);

                TempData["id"] = JsonConvert.SerializeObject(nourriture.Id);

                return(RedirectToAction("DetailsResto", "Service"));
            }


            return(View(model));
        }