public IActionResult create(EmployeeVM emp)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //save photo

                    emp.PhotoName = uploadeFile.uploade(emp.PhotoURL, "/wwwroot/files/photoes/");
                    emp.CVName    = uploadeFile.uploade(emp.CVURL, "/wwwroot/files/cvs/");
                    repo.Add(emp);
                    return(RedirectToAction("index"));
                }
                else
                {
                    var data = department.Get();
                    ViewBag.depts = new SelectList(data, "id", "DepartmentName");
                    return(View(emp));
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("create"));
            }
        }
Пример #2
0
 public IActionResult Create(EmployeeCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         string fileName = null;
         if (model.Avatar != null)
         {
             // To make the filename always unique
             fileName = Guid.NewGuid().ToString() + "_" + model.Avatar.FileName;
             string filePath = Path.Combine(host.WebRootPath, "media", fileName);
             model.Avatar.CopyTo(new FileStream(filePath, FileMode.Create));
         }
         Employee newEmployee = new Employee()
         {
             Avatar     = fileName,
             Department = model.Department,
             Email      = model.Email,
             Name       = model.Name
         };
         _employeeRepo.Add(newEmployee);
         return(RedirectToAction("details", new { id = newEmployee.ID }));
     }
     else
     {
         return(View());
     }
 }
Пример #3
0
        public void Create(
            Employee employee,
            int departmentId,
            int positionId)
        {
            if (employee == null)
            {
                throw new ArgumentNullException(nameof(employee));
            }
            var foundDepartment = _departmentRepo.GetById(departmentId);

            if (foundDepartment == null)
            {
                throw new ArgumentNullException(nameof(foundDepartment));
            }
            employee.Department = foundDepartment;

            var foundPosition = _positionRepo.GetById(positionId);

            if (foundPosition == null)
            {
                throw new ArgumentNullException(nameof(foundPosition));
            }
            employee.Position = foundPosition;

            _repository.Add(employee);
        }
        public IActionResult Create(EmployeeCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniquefilename = null;
                if (model.Photo != null)
                {
                    string upLoadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                    uniquefilename = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;

                    string filePath = Path.Combine(upLoadsFolder, uniquefilename);
                    model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }


                Employee newEmployee = new Employee
                {
                    Name       = model.Name,
                    Email      = model.Email,
                    Department = model.Department,
                    PhotoPath  = uniquefilename
                };
                _employeeRepo.Add(newEmployee);
                //Employee newemployee = _employeeRepo.Add(employee);
                return(RedirectToAction("Details", new { id = newEmployee.Id }));
            }
            else
            {
                return(View());
            }
        }
Пример #5
0
        public async Task <ActionResult <int> > SaveUser(Users user)
        {
            try
            {
                Employee employee = new Employee();
                employee.Name              = user.EmployeeName;
                employee.Password          = EncryptedPassword(user.Password);
                employee.Email             = user.Email;
                employee.CreationTimeStamp = DateTime.UtcNow;
                employee.IsActive          = true;
                employee.IsLocked          = false;
                employee.PAN = EncryptedPassword(user.PAN);
                employee.ProfilePicturePath = user.ProfilePicture;
                var hasAdded = await _employeeRepo.Add(employee);

                if (hasAdded > 0)
                {
                    return(hasAdded);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(0);
        }
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                if (Photo != null)
                {
                    // If a new photo is uploaded, the existing photo must be
                    // deleted. So check if there is an existing photo and delete
                    if (Employee.Photopath != null)
                    {
                        string filePath = Path.Combine(webHostEnvironment.WebRootPath,
                                                       "images", Employee.Photopath);
                        System.IO.File.Delete(filePath);
                    }
                    // Save the new photo in wwwroot/images folder and update
                    // PhotoPath property of the employee object
                    Employee.Photopath = ProcessUploadedFile();
                }

                if (Employee.ID > 0)
                {
                    Employee = employeeRepositoryint.Update(Employee);
                }

                else
                {
                    Employee = employeeRepositoryint.Add(Employee);
                }
                return(RedirectToPage("Index"));
            }
            return(Page());
        }
Пример #7
0
        public IActionResult Create(EmployeeCreateView employee)
        {
            if (ModelState.IsValid)
            {
                string filepath = null;
                if (employee.Photo != null)
                {
                    string uploads = Path.Combine(hosting_Environment.WebRootPath, "images");
                    filepath = Guid.NewGuid().ToString() + "_" + employee.Photo.FileName;
                    string path = Path.Combine(uploads, filepath);
                    employee.Photo.CopyTo(new FileStream(path, FileMode.Create));
                }

                Employee newEmployee = new Employee
                {
                    Name     = employee.Name,
                    Email    = employee.Email,
                    Dep      = employee.Dep,
                    EmpPhoto = filepath
                };

                employee_Repo.Add(newEmployee);

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

            return(View());
        }
Пример #8
0
        public async Task <Guid> Create(EmployeeCreateRequest request)
        {
            var employee = EmployeeAggregate.CreateFromRequest(request);

            await _repo.Add(employee);

            return(employee.Id);
        }
 public IActionResult Create(Employee employee)
 {
     if (ModelState.IsValid)
     {
         Employee newEmployee = _repository.Add(employee);
         return(RedirectToAction("Details", new { id = newEmployee.EmployeeId }));
     }
     return(View());
 }
Пример #10
0
 public IActionResult Create(Employee employee)
 {
     if (ModelState.IsValid)
     {
         Employee newemployee = _EmplolyeeRepo.Add(employee);
         return(RedirectToAction("Index", new { id = newemployee.ID }));
     }
     return(View());
 }
Пример #11
0
        public void UpdateAll(List <EmployeeFetched> employeesFetched)
        {
            var employees = _repository.GetAll();

            // Delete should be cascade if it's necessary
            // foreach (var employee in employees)
            // {
            //     if (!employeesFetched.Select(v => v.Id).Contains(employee.Id))
            //         _repository.Delete(employee);
            // }
            foreach (var employeeFetched in employeesFetched.Where(v => v.Post != null && v.Department != null))
            {
                var foundEmployee = employees.SingleOrDefault(v => v.Id == employeeFetched.Id);
                if (foundEmployee == null)
                {
                    _repository.Add(employeeFetched.ToEmployee());
                }
                else
                {
                    var e = employeeFetched.ToEmployee();

                    var wasChanged = false;
                    var fullName   = e.Fullname.Trim();
                    if (foundEmployee.Fullname != fullName)
                    {
                        foundEmployee.Fullname = fullName;
                        wasChanged             = true;
                    }
                    var name = e.Name.Trim();
                    if (foundEmployee.Fullname != name)
                    {
                        foundEmployee.Fullname = name;
                        wasChanged             = true;
                    }
                    if (foundEmployee.IsActive != e.IsActive)
                    {
                        foundEmployee.IsActive = e.IsActive;
                        wasChanged             = true;
                    }
                    if (foundEmployee.PositionId != e.PositionId)
                    {
                        foundEmployee.PositionId = e.PositionId;
                        wasChanged = true;
                    }
                    if (foundEmployee.DepartmentId != e.DepartmentId)
                    {
                        foundEmployee.PositionId = e.PositionId;
                        wasChanged = true;
                    }
                    if (wasChanged)
                    {
                        _repository.Update(foundEmployee);
                    }
                }
            }
        }
Пример #12
0
        public async Task <Guid> Create(EmployeeRequest employeeRequest)
        {
            var employee = new Employee
            {
                Id     = Guid.NewGuid(),
                UserId = employeeRequest.UserId
            };
            await _employeeRepo.Add(employee);

            return(employee.Id);
        }
Пример #13
0
 public void AddOrUpdate(EmployeeViewModel employeeViewModel)
 {
     if (employeeViewModel.Id == 0)
     {
         _employeeRepo.Add(_mapper.Map <Employee>(employeeViewModel));
     }
     else
     {
         _employeeRepo.Update(_mapper.Map <Employee>(employeeViewModel));
     }
 }
        public ActionResult Add(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                ProcessFileToServer(model);

                _empRepo.Add(model);
                return(RedirectToAction("info", new { id = model.ID }));
            }
            return(View());
        }
Пример #15
0
        public async Task <Guid> CreateEmployee(EmployeeDTO employeeDTO)
        {
            Employee employee = new Employee
            {
                Id        = Guid.NewGuid(),
                UserId    = employeeDTO.UserId,
                IsDeleted = false,
                Sheets    = new List <Sheet>()
            };
            await _repo.Add(employee);

            return(employee.Id);
        }
 public ActionResult Index(EmployeeVM em)
 {
     if (ModelState.IsValid)
     {
         Employee newEmployee = new Employee()
         {
             Name    = em.Name,
             Address = em.Address,
             Age     = em.Age
         };
         _repo.Add(newEmployee);
     }
     return(View());
 }
        public IActionResult Create(EmployeeCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFilename = ProcessUploadedFile(model);

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

                _employeeRepo.Add(newEmployee);
                return(RedirectToAction("details", new { id = newEmployee.Id }));
            }
            return(View());
        }
Пример #18
0
        public IActionResult Create(DTOs.Employee model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;

                // If the Photo property on the incoming model object is not null, then the user
                // has selected an image to upload.
                if (model.Photo != null)
                {
                    // The image must be uploaded to the images folder in wwwroot
                    // To get the path of the wwwroot folder we are using the inject
                    // HostingEnvironment service provided by ASP.NET Core
                    string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                    // To make sure the file name is unique we are appending a new
                    // GUID value and and an underscore to the file name
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    // Use CopyTo() method provided by IFormFile interface to
                    // copy the file to wwwroot/images folder
                    model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                Employee newEmployee = new Employee
                {
                    Name       = model.Name,
                    Email      = model.Email,
                    Department = (Dept)model.Department,
                    // Store the file name in PhotoPath property of the employee object
                    // which gets saved to the Employees database table
                    PhotoPath = uniqueFileName
                };

                var emp = _employeeRepository.Add(newEmployee);
                return(RedirectToAction("details", new { id = emp.Id }));
            }

            return(View());
        }
        // GET api/values
        //public PageResult<Employee> Get()
        //{
        //    //ClientRepo.Add(new Employee { Name = "sds"});
        //    //unitOfWork.SaveChanges();

        //    //return ClientRepo.GetPages(1);
        //    //return new string[] { "value1", "value2" };
        //}

        // GET api/values/5
        //public PageResult<Employee> Get(int id)
        //{
        //    return ClientRepo.GetPages(id);
        //}

        // POST api/values
        public void Post([FromBody] Employee emp)
        {
            ClientRepo.Add(emp);
            unitOfWork.SaveChanges();
        }
Пример #20
0
 public Employee CreateEmployee(Employee entity)
 {
     return(EmployeeRepo.Add(entity));
 }