public ActionResult Update(data.employee employee, long id, Boolean isAdmin, Boolean isSeller) { employee.employeeId = id; employee.isActive = true; _employees.Update(employee); #region rols //get user users _user = new users(); data.user user = _user.GetOneByEmployeeId(id); //get list of rols by id user users_x_rols _users_x_rols = new users_x_rols(); var listUser_x_rols = _users_x_rols.GetAllByUserId(user.userId); data.user_x_rols user_x_rols = new data.user_x_rols(); user_x_rols.userId = listUser_x_rols.FirstOrDefault().userId; //this bs is because if I use _users_x_rols generete conflict with tha primary key users_x_rols deleteElemento = new users_x_rols(); if (isAdmin) { //check if exist the administrator rol if (listUser_x_rols.Where(x => x.rolId == 1).Count() == 0) { user_x_rols.rolId = 1; _users_x_rols.Insert(user_x_rols); } } else { //check if exist the administrator rol and check than exist one rol in tha user if (listUser_x_rols.Where(x => x.rolId == 1).Count() != 0 && (listUser_x_rols.Count() >= 2 || isSeller)) { deleteElemento.Delete(listUser_x_rols.Where(x => x.rolId == 1).FirstOrDefault()); } } if (isSeller) { //check if exist the seller rol if (listUser_x_rols.Where(x => x.rolId == 2).Count() == 0) { user_x_rols.rolId = 2; _users_x_rols.Insert(user_x_rols); } } else { //check if exist the seller rol and check than exist one rol in tha user if (listUser_x_rols.Where(x => x.rolId == 2).Count() != 0 && (listUser_x_rols.Count() >= 2 || isAdmin)) { deleteElemento.Delete(listUser_x_rols.Where(x => x.rolId == 2).FirstOrDefault()); } } #endregion rols return(RedirectToAction("Index")); }
public ActionResult ChangePassword(String password) { var employeeId = Int64.Parse(Session["employeeId"].ToString()); keys _keys = new keys(); data.AES aes = new data.AES(); var key = _keys.GetOneById(1); users _users = new users(); var user = _users.GetOneByEmployeeId(employeeId); user.userPassword = aes.Encriptar(password, key.C_Key, key.C_IV); //I need a second BS user for update users _users02 = new users(); try { _users02.Update(user); return(Json(new { sucess = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(null); } }