示例#1
0
 public IActionResult create(HomecreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         string uniqueFileName = ProcessUploadFile(model);
         Home   home           = new Home
         {
             Name       = model.Name,
             Email      = model.Email,
             Department = model.Department,
             photopath  = uniqueFileName
         };
         _employeerepository.add(home);
         return(RedirectToAction("design", new { id = home.id }));
     }
     return(View());
 }
示例#2
0
        private string ProcessUploadFile(HomecreateViewModel model)
        {
            string uniqueFileName = null;

            if (model.photos != null && model.photos.Count > 0)
            {
                foreach (IFormFile photo in model.photos)
                {
                    string UpLoadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                    string filepath = Path.Combine(UpLoadsFolder, uniqueFileName);
                    photo.CopyTo(new FileStream(filepath, FileMode.Create));
                }
            }

            return(uniqueFileName);
        }