Пример #1
0
 public IActionResult Create(HomeCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         var employee = new Employee()
         {
             Fullname   = model.Fullname,
             Email      = model.Email,
             Department = model.Department
         };
         var fileName = string.Empty;
         if (model.Avatar != null)
         {
             string uploadFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
             fileName = $"{Guid.NewGuid()}_{model.Avatar.FileName}";
             var filePath = Path.Combine(uploadFolder, fileName);
             using (var fs = new FileStream(filePath, FileMode.Create))
             {
                 model.Avatar.CopyTo(fs);
             }
         }
         employee.AvatarPath = fileName;
         var newEmp = employeeRespository.Create(employee);
         return(RedirectToAction("Details", new { id = newEmp.Id }));
     }
     return(View());
 }
Пример #2
0
        public IActionResult Create(Employees employee)//RedirectToActionResult
        {
            if (ModelState.IsValid)
            {
                employee = _employeeRespository.Create(employee);

                return(RedirectToAction("details", new { id = employee.Id }));
            }
            return(View());
        }