public ActionResult EditUser(UserAdminVM model)
        {
            EmployeeRepo    eRepo = new EmployeeRepo();
            List <Employee> Users = eRepo.GetAllEmployees();
            List <Role>     Roles = eRepo.GetAllRoles();

            model.Users = Users;
            model.Roles = Roles;
            model.SetRoleChoice(Roles);
            var userManager = HttpContext.GetOwinContext().GetUserManager <UserManager <AppUser> >();

            if (ModelState.IsValid)
            {
                eRepo.EditEmployee(model.NewUser);
                if (model.OldRoleName != null)
                {
                    if (model.NewUser.RoleName != model.OldRoleName)
                    {
                        userManager.RemoveFromRole(model.NewUser.EmployeeID, model.OldRoleName);
                        userManager.AddToRole(model.NewUser.EmployeeID, model.NewUser.RoleName);
                    }
                }
                else
                {
                    userManager.AddToRole(model.NewUser.EmployeeID, model.NewUser.RoleName);
                }

                UserAdminVM m2 = new UserAdminVM();

                m2.Users = Users;
                m2.Roles = Roles;
                m2.SetRoleChoice(Roles);
                return(RedirectToAction("EmployeeAdmin", m2));
            }
            else
            {
                return(View("EditUser", model));
            }
        }
示例#2
0
        public HttpResponseMessage EmployeeUpdate(EmployeeModel employee_details)
        {
            HttpResponseMessage Response = null;

            try
            {
                if (employee_details != null)
                {
                    Employee existingInstance = EmployeeRepo.GetEmployeeById(employee_details.id);
                    if (existingInstance == null)
                    {
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_403", "Employee record doesnot exists!", "Employee record doesnot exists!"));
                    }
                    else//(if existingInstance != null)
                    {
                        Employee employee = new Employee();
                        employee.id                       = employee_details.id;
                        employee.first_name               = employee_details.first_name;
                        employee.last_name                = employee_details.last_name;
                        employee.email                    = employee_details.email;
                        employee.date_of_birth            = employee_details.date_of_birth;
                        employee.date_of_joining          = employee_details.date_of_joining;
                        employee.contact_no               = employee_details.contact_no;
                        employee.reporting_to             = employee_details.reporting_to;
                        employee.year_of_experience       = Decimal.Parse(employee_details.Year_of_experience);
                        employee.gender                   = employee_details.gender;
                        employee.pan_no                   = employee_details.pan_no;
                        employee.bank_account_no          = employee_details.bank_account_no;
                        employee.emergency_contact_no     = employee_details.emergency_contact_no;
                        employee.emergency_contact_person = employee_details.emergency_contact_person;
                        employee.PF_no                    = employee_details.PF_no;
                        employee.medical_insurance_no     = employee_details.medical_insurance_no;
                        employee.blood_group              = employee_details.blood_group;
                        employee.designation              = employee_details.designation_id;
                        employee.created_on               = existingInstance.created_on;

                        employee.user_id = existingInstance.user_id;

                        User_role userrole_instance = EmployeeRepo.GetUserRoleByUserid(employee.user_id);
                        userrole_instance.role_id = employee_details.role_id;
                        EmployeeRepo.UpdateUserRole(userrole_instance);

                        Salary_Structure active_sal_instance = SalaryRepo.GetSalaryStructureByEmpId(employee.id);

                        if (active_sal_instance != null && active_sal_instance.ctc != employee_details.ctc)
                        {
                            active_sal_instance.is_active = 0;
                            active_sal_instance.to_date   = DateTime.Now;
                            SalaryRepo.UpdateSalaryStructure(active_sal_instance);

                            Salary_Structure new_sal_structure = new Salary_Structure();
                            new_sal_structure           = SalaryCalculation.CalculateSalaryStructure(employee_details.ctc);
                            new_sal_structure.emp_id    = employee.id;
                            new_sal_structure.is_active = 1;
                            new_sal_structure.from_date = DateTime.Now;
                            new_sal_structure.to_date   = null;
                            SalaryRepo.CreateSalaryStructure(new_sal_structure);
                        }
                        EmployeeRepo.EditEmployee(employee);
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Employee details updated successfully!", "Employee details updated successfully!"));
                    } //(existingInstance != null) ELSE PART
                }     //employee_details != null IF PART
                else  //IF employee_details == null
                {
                    Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_102", "Invalid Input", "Please check input Json"));
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(Response);
        }
示例#3
0
 // PUT: api/Employee/5
 public void Put(int id, Employee value)
 {
     value.eid = id;
     EmployeeRepo.EditEmployee(value);
 }