示例#1
0
        public async Task <IActionResult> Create(CreateEmployeViewModel createEmployeViewModel)
        {
            if (ModelState.IsValid)
            {
                Personne personne = new Personne
                {
                    Nom           = createEmployeViewModel.Nom,
                    Prenom        = createEmployeViewModel.Prenom,
                    Sexe          = createEmployeViewModel.Sexe,
                    DateNaissance = createEmployeViewModel.DateNaissance,
                    NumSecu       = createEmployeViewModel.NumSecu,
                    Discriminator = "Employe"
                };
                _context.Add(personne);
                await _context.SaveChangesAsync();

                string telephone = phoneRegex.Replace(createEmployeViewModel.Telephone, "($1) $2-$3");

                Employe employe = new Employe
                {
                    EmployeId = personne.PersonneId,
                    Personne  = personne,
                    Externe   = createEmployeViewModel.Externe,
                    Poste     = createEmployeViewModel.Poste,
                    Telephone = telephone
                };
                _context.Add(employe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(createEmployeViewModel));
        }
        public IActionResult Create(CreateEmployeViewModel model)
        {
            if (ModelState.IsValid)
            {
                String Uniquename = ProcessorUploadFile(model);
                ////uploadd muilti img
                //if (model.Photes != null && model.Photes.Count > 0)
                //{
                //    foreach (var item in model.Photes)
                //    {
                //        String UploadFolder = Path.Combine(_hostingEnvirnment.WebRootPath, "Image");
                //        Uniquename = Guid.NewGuid().ToString() + "_" + item.FileName;
                //        String filename = Path.Combine(UploadFolder, Uniquename);
                //        item.CopyTo(new FileStream(filename, FileMode.Create));
                //    }
                //}
                Employee employee = new Employee()
                {
                    Name       = model.Name,
                    Email      = model.Email,
                    Department = model.Department,
                    PhotoPath  = Uniquename
                };
                _employeeREpository.Add(employee);
                return(RedirectToAction("Details", new { id = employee.Id }));

                //   return RedirectToAction("Details", new { id = employee1.Id });
            }
            return(View());
        }
示例#3
0
        public IActionResult Index()
        {
            //var loggedInUser = LoggedInUser();
            //var profile = _context.Users.Where(x => x.Id == User.Identity.Name);

            //return View(profile);

            CreateEmployeViewModel emp = new CreateEmployeViewModel();

            var profile = _context.Users.FirstOrDefault(x => x.UserName == emp.Username);

            return(View(profile));
        }
示例#4
0
        private string fileUploadProcess(CreateEmployeViewModel model)
        {
            string uniquePath;
            string uploadFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images/");

            uniquePath = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
            string filePath = Path.Combine(uploadFolder, uniquePath);

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

            return(uniquePath);
        }
示例#5
0
        private string ProcessUploadedFile(CreateEmployeViewModel model)
        {
            string PhotoName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Images");
                PhotoName = DateTime.Now.ToString("yyyyMMddhhmmss") + "-" + model.Photo.FileName;
                //to save Uniqfile name should use time stemp or Guid method
                //PhotoName = Guid.NewGuid().ToString() + "-" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, PhotoName);
                using (var fileStrean = new FileStream(filePath, FileMode.Create))
                {
                    model.Photo.CopyTo(fileStrean);
                }
            }

            return(PhotoName);
        }
示例#6
0
        public IActionResult Create(CreateEmployeViewModel model)
        {
            if (ModelState.IsValid)
            {
                string   PhotoName   = ProcessUploadedFile(model);
                Employee newEmployee = new Employee
                {
                    Name       = model.Name,
                    Email      = model.Email,
                    Dob        = model.Dob,
                    Gender     = model.Gender,
                    Department = model.Department,
                    PhotoPath  = PhotoName
                };
                empRepository.Add(newEmployee);

                return(RedirectToAction("Details", new { id = newEmployee.Id }));
            }
            return(View());
        }
        //use CreateEmployeViewModel instrad of EditEmployeViewModel becouse CreateEmployeViewModelis the parent
        private string ProcessorUploadFile(CreateEmployeViewModel model)
        {
            string Uniquename = null;

            if (model.Photes != null && model.Photes.Count > 0)
            {
                foreach (var item in model.Photes)
                {
                    String UploadFolder = Path.Combine(_hostingEnvirnment.WebRootPath, "Image");
                    Uniquename = Guid.NewGuid().ToString() + "_" + item.FileName;
                    String filename = Path.Combine(UploadFolder, Uniquename);
                    //useing is used to when this blockexecuted immedaitly dispose
                    using (var filestream = new FileStream(filename, FileMode.Create))
                    {
                        item.CopyTo(filestream);
                    }
                }
            }

            return(Uniquename);
        }
示例#8
0
        public IActionResult Create(CreateEmployeViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniquePath = null;
                if (model.Photo != null)
                {
                    fileUploadProcess(model);
                }

                EmployeeModel employeeModel = new EmployeeModel
                {
                    Name       = model.Name,
                    Email      = model.Email,
                    Department = model.Department,
                    PhotoPath  = uniquePath,
                };

                _employeeRepository.AddEmployee(employeeModel);
            }
            ModelState.Clear();
            return(View());
        }
示例#9
0
        // GET: Employes/Create
        public IActionResult Create()
        {
            CreateEmployeViewModel createEmployeViewModel = new CreateEmployeViewModel();

            return(View(createEmployeViewModel));
        }