Example #1
0
        public IActionResult Create(EmployeeCreateModalView modal)
        {
            if (ModelState.IsValid)
            {
                string   UniqFilePath = GetUniqueFilePath(modal);
                Employee emp          = new Employee()
                {
                    Name       = modal.Name,
                    Department = modal.Department,
                    FilePath   = UniqFilePath
                };

                Employee nemp = _emprep.Add(emp);
                return(RedirectToAction("details", new { nemp.Id }));
            }
            return(View());
        }
Example #2
0
        private string GetUniqueFilePath(EmployeeCreateModalView modal)
        {
            string UniqFilePath = null;

            if (modal.Photo != null)
            {
                string UploadFolder = Path.Combine(hostingEnvironment.WebRootPath, "Images");
                UniqFilePath = Guid.NewGuid().ToString() + "_" + modal.Photo.FileName;
                string filePath = Path.Combine(UploadFolder, UniqFilePath);
                using (var filePanthNew = new FileStream(filePath, FileMode.Create))
                {
                    modal.Photo.CopyTo(filePanthNew);
                }
            }

            return(UniqFilePath);
        }