Ejemplo n.º 1
0
        public IActionResult CreatLight(CreatLightViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;

                if (model.Photos != null && model.Photos.Count > 0)
                {
                    uniqueFileName = ProcessUpLoadedFile(model);
                }
                Light newLight = new Light
                {
                    Name      = model.Name,
                    Iswell    = model.Iswell,
                    Iswork    = model.Iswork,
                    Lng       = model.Lng,
                    Lat       = model.Lat,
                    Control   = model.Control,
                    Celle     = model.Celle,
                    Sens      = model.Sens,
                    PhotoPath = uniqueFileName
                };
                _lightRepository.AddLight(newLight);

                return(RedirectToAction("Creatsucced"));
            }
            return(View());
        }
Ejemplo n.º 2
0
        private string ProcessUpLoadedFile(CreatLightViewModel model)
        {
            string uniqueFileName = null;


            if (model.Photos.Count > 0)
            {
                foreach (var photo in model.Photos)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");

                    uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;

                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);


                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        photo.CopyTo(fileStream);
                    }
                }
            }

            return(uniqueFileName);
        }