Beispiel #1
0
        public IActionResult Create(HomeCreateViewModel newemployee)
        {
            if (ModelState.IsValid)
            {
                string        UniqueFileName = null;
                List <string> fileNames      = new List <string>();
                if (newemployee.FileName != null && newemployee.FileName.Count > 0)
                {
                    string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "Files");
                    foreach (var file in newemployee.FileName)
                    {
                        UniqueFileName = Guid.NewGuid() + "_" + file.FileName;
                        string filePath = Path.Combine(uploadsFolder, UniqueFileName);
                        file.CopyTo(new FileStream(filePath, FileMode.Create));
                        fileNames.Add(UniqueFileName);
                    }
                    //UniqueFileName = Guid.NewGuid() + "_" + newemployee.FileName.ForEach;
                    //string filePath = Path.Combine(uploadsFolder, UniqueFileName);
                    //newemployee.FileName.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                Employee empValue = _employeeRepository.AddEmployee(new Employee {
                    Name       = newemployee.Name,
                    Department = newemployee.Department,
                    FileName   = fileNames.Count() > 0 ? String.Join(';', fileNames) : null
                });

                return(new RedirectToActionResult("Details", "Home", new { id = empValue.ID }));
            }

            return(View());
        }
Beispiel #2
0
 public IActionResult Create([Bind] Employee employee)
 {
     if (ModelState.IsValid)
     {
         objemployee.AddEmployee(employee);
     }
     return(RedirectToAction("Create"));
     //return RedirectToAction(nameof(Details), new { id = emp.ID });
 }