Exemplo n.º 1
0
 public void EditEmpoyeeAdmin(int id, UserEditVIewModel vm)
 {
     if (!CheckUserExistForEdit(id, vm.Username))
     {
         var userFromDb = DB.Users.Include("UserRoles").FirstOrDefault(x => x.Id == id && x.Active == true);
         userFromDb.Username = vm.Username;
         //only admin can change teamLeader to employee
         if (!userFromDb.TeamLeaderId.HasValue && vm.TeamLeaderId.HasValue)
         {     //change teamLeader to employee
             if (!CheckTlHaveEmployees(userFromDb.Id))
             { //can`t change team lider to employee if tl have employees
                 userFromDb.UserRoles.FirstOrDefault(x => x.UserId == vm.Id).RoleId = (int)vm.RoleId;
                 userFromDb.TeamLeaderId = vm.TeamLeaderId;
             }
         }
         else if (userFromDb.TeamLeaderId.HasValue && !vm.TeamLeaderId.HasValue)
         {//change employee to teamLeader
             userFromDb.TeamLeaderId = null;
             userFromDb.UserRoles.FirstOrDefault(x => x.UserId == vm.Id).RoleId = (int)vm.RoleId;
         }
         else if (userFromDb.TeamLeaderId.HasValue && vm.TeamLeaderId.HasValue)
         {//set new tl for employee
             userFromDb.TeamLeaderId = vm.TeamLeaderId;
         }
         DB.SaveChanges();
     }
     ;
 }
Exemplo n.º 2
0
 public void EditEmpoyeeTeamLeader(int id, UserEditVIewModel vm)
 {
     if (!CheckUserExistForEdit(id, vm.Username))
     {
         DB.Users.FirstOrDefault(x => x.Id == id && x.Active == true).Username = vm.Username;
         DB.SaveChanges();
     }
     ;
 }
Exemplo n.º 3
0
 public ActionResult Edit(int id, UserEditVIewModel vm)
 {
     try
     {
         bool IsAdmin = User.IsInRole("Admin");
         if (!IsAdmin)
         {
             BLL.EditEmpoyeeTeamLeader(id, vm);
             return(RedirectToAction("Employees"));
         }
         if (vm.RoleId != 2 && !vm.TeamLeaderId.HasValue)
         {
             return(View(vm));
         }
         BLL.EditEmpoyeeAdmin(id, vm);
         return(RedirectToAction("Employees"));
     }
     catch
     {
         return(View());
     }
 }