Example #1
0
        public IActionResult Create(EmployeeCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string   uniqueFileName = ProcessUploadedFile(model);
                int      id             = (int)model.Departmennt;
                Employee newEmployee    = new Employee
                {
                    Name        = model.Name,
                    Email       = model.Email,
                    Surname     = model.Surname,
                    Departmennt = model.Departmennt,
                    PhotoPath   = uniqueFileName,
                    Depo        = _departmentRepository.FindDepartment(id)
                };
                _empRepository.Add(newEmployee);

                return(RedirectToAction("details", new { id = newEmployee.ID }));
            }
            return(View());
        }
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                if (Photo != null)
                {
                    if (Employee.PhotoPath != null)
                    {
                        string FilePath = Path.Combine(_WebHostEnviroment.WebRootPath, "images", Employee.PhotoPath);

                        if (Employee.PhotoPath != "noimage.png")
                        {
                            System.IO.File.Delete(FilePath);
                        }
                    }

                    Employee.PhotoPath = ProcessUploadedFile();
                }

                if (Employee.Id == 0)
                {
                    _employeRepository.Add(Employee);
                    TempData["SuccessMessage"] = $"Adding {Employee.Name} successful";
                }
                else
                {
                    _employeRepository.Update(Employee);
                    TempData["SuccessMessage"] = $"Update {Employee.Name} successful";
                }



                return(RedirectToPage("Employes"));
            }


            return(Page());
        }
Example #3
0
        public IActionResult Create(EmployeeCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (model.Photo != null)
                {
                    string uploadsFolder = ProcesUploadedFile(model);
                }

                Employee newEmployee = new Employee
                {
                    Name       = model.Name,
                    Email      = model.Email,
                    Department = model.Department,
                    PhotoPath  = uniqueFileName
                };

                _employeRepository.Add(newEmployee);
                return(RedirectToAction("details", new { id = newEmployee.Id }));
            }
            return(View());
        }
 public void Add(FundingAPI.Employe entity)
 {
     _repos.Add(entity.ToDAL());
 }