Esempio n. 1
0
        public bool Delete(Employee employee)
        {
            try {
                _dataService.Employees.Remove(employee);
                _dataService.SaveChanges();
                return true;
            }

            catch (Exception exception)
            { return false; }
        }
Esempio n. 2
0
        public bool Update(Employee employee)
        {
            try {

                _dataService.Entry(employee).State = EntityState.Modified;
                _dataService.SaveChanges();
                return true;
            }
            catch (Exception ex)
            { return false; }
        }
Esempio n. 3
0
        public bool Create(Employee employee)
        {
            try {

                _dataService.Employees.Add(employee);
                _dataService.SaveChanges();
                return true;
            }

            catch (Exception ex)
            {
                //throw (ex);
                return false;
            }
        }
Esempio n. 4
0
        public ActionResult Create(EmployeeVM employeeVM)
        {
            if (ModelState.IsValid)
            {
                Employee objEmp = new Employee();
                objEmp.EmployeeID = employeeVM.EmployeeID;
                objEmp.FirstName = employeeVM.FirstName;
                objEmp.LastName = employeeVM.LastName;
                objEmp.Address = employeeVM.Address + employeeVM.Addressline;
                objEmp.DateOfBirth = employeeVM.DateOfBirth;
                objEmp.HiredDate = employeeVM.HiredDate;
                objEmp.Email = employeeVM.Email;
                objEmp.Phone = employeeVM.Phone;
                objEmp.Zipcode = employeeVM.Zipcode;
                objEmp.UserName = employeeVM.UserName;
                objEmp.Password = employeeVM.Password;

                objEmp.ConfirmPassword = employeeVM.ConfirmPassword;

                objEmp.State = _stateService.GetState(employeeVM.SelectedStateID);
                objEmp.City = _cityService.GetCity(employeeVM.SelectedCityID);
                objEmp.JobTitle = _jobService.getJob(employeeVM.SelectedJobID);
                objEmp.Department = _departmentService.getDepartment(employeeVM.SelectedDeptID);

                objEmp.Gender = Convert.ToInt16(employeeVM.Gender);

                //City city = _cityService.GetCity(employeeVM.SelectedCityID);

                //State state = _stateService.GetState(employeeVM.SelectedStateID);

                //JobTitle Job = db.JobTitles.Where(j => j.JobID == employeeVM.SelectedJobID).SingleOrDefault();

                //Department Dept = db.Departments.Where(d => d.DepartmentID == employeeVM.SelectedDeptID).SingleOrDefault();

                objEmp.WorkingDays = new List<WorkingDay>();
                foreach (int id in employeeVM.SelectedWorkingDayIDs)
                {
                    WorkingDay workingdays = _workingdayService.getSelectedWorkingday(id);
                    objEmp.WorkingDays.Add(workingdays);

                }

                objEmp.Shifts = new List<Shift>();
                foreach (int selectedId in employeeVM.Shifts.Where(s => s.Checked == true).Select( x=>x.ID))
                {
                    Shift shift = _shiftService.getShift(selectedId);
                    objEmp.Shifts.Add(shift);
                }

                //db.Employees.Add(objEmp);
                if (_empService.Create(objEmp) == true)
                    ViewData["Status"] = "Employee " + objEmp.FirstName + "saved successfully";
                else
                    ViewData["Status"] = "Unexpected error occurred while saving employee " + objEmp.FirstName;
                //_empService.Create(objEmp);

                return RedirectToAction("Index");
            }
            else
                employeeVM = FillLists(employeeVM);

            return View(employeeVM);
        }
Esempio n. 5
0
        public ActionResult Edit(EmployeeVM employeeVM)
        {
            if (ModelState.IsValid)
            {
                Employee objEmp = new Employee();
                objEmp.EmployeeID = employeeVM.EmployeeID;
                objEmp.FirstName = employeeVM.FirstName;
                objEmp.LastName = employeeVM.LastName;
                objEmp.Address = employeeVM.Address + employeeVM.Addressline;
                objEmp.DateOfBirth = employeeVM.DateOfBirth;
                objEmp.HiredDate = employeeVM.HiredDate;
                objEmp.Email = employeeVM.Email;
                objEmp.Phone = employeeVM.Phone;
                objEmp.Zipcode = employeeVM.Zipcode;
                objEmp.UserName = employeeVM.UserName;
                objEmp.Password = employeeVM.Password;

                objEmp.ConfirmPassword = employeeVM.ConfirmPassword;

                objEmp.State = _stateService.GetState(employeeVM.SelectedStateID);
                objEmp.City = _cityService.GetCity(employeeVM.SelectedCityID);
                objEmp.JobTitle = _jobService.getJob(employeeVM.SelectedJobID);
                objEmp.Department = _departmentService.getDepartment(employeeVM.SelectedDeptID);

                objEmp.Gender = Convert.ToInt16(employeeVM.Gender);

                objEmp.WorkingDays = new List<WorkingDay>();
                foreach (int id in employeeVM.SelectedWorkingDayIDs)
                {
                    WorkingDay workingdays = _workingdayService.getSelectedWorkingday(id);
                    objEmp.WorkingDays.Add(workingdays);

                }

                objEmp.Shifts = new List<Shift>();
                foreach (int id in employeeVM.Shifts.Where(s => s.Checked == true).Select(x=>x.ID))
                {
                    Shift shift = _shiftService.getShift(id);
                    objEmp.Shifts.Add(shift);
                }

                //db.Entry(objEmp).State = EntityState.Modified;
                //db.SaveChanges();
                if (_empService.Update(objEmp) == true)
                    //ViewData["Status"] = "Employee " + objEmp.FirstName + "saved successfully";
                    TempData["status"] = "Employee   " + objEmp.FirstName + "   saved successfully";
                else
                   // ViewData["Status"] = "Unexpected error occurred while saving employee " + objEmp.FirstName;
                    TempData["status"] = "Unexpected error occurred while saving employee   " + objEmp.FirstName;

                return RedirectToAction("Index");
            }
            else
            {
                employeeVM = FillListsEdit(employeeVM);
                employeeVM.AllCity = new SelectList(_cityService.GetAllCities(employeeVM.SelectedStateID), "CityID", "CityName");
            }

            return View(employeeVM);
        }