public UsersRole GetUserById(string userId) { UsersRole user = new UsersRole(); using (var cn = new SqlConnection(Settings.GetConnectionString())) { SqlCommand cmd = new SqlCommand("GetUserById", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", userId); cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) { user.UserId = dr["UserId"].ToString(); user.FirstName = dr["FirstName"].ToString(); user.LastName = dr["LastName"].ToString(); user.Email = dr["Email"].ToString(); user.Role = dr["Role"].ToString(); user.RoleId = dr["RoleId"].ToString(); } } return(user); } }
public IEnumerable <UsersRole> GetAllUsers() { List <UsersRole> users = new List <UsersRole>(); using (var cn = new SqlConnection(Settings.GetConnectionString())) { SqlCommand cmd = new SqlCommand("UsersSelectAll", cn); cmd.CommandType = CommandType.StoredProcedure; cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { UsersRole currentRow = new UsersRole(); currentRow.UserId = dr["UserId"].ToString(); currentRow.FirstName = dr["FirstName"].ToString(); currentRow.LastName = dr["LastName"].ToString(); currentRow.Email = dr["Email"].ToString(); currentRow.Role = dr["Role"].ToString(); currentRow.RoleId = dr["RoleId"].ToString(); users.Add(currentRow); } } } return(users); }
public ActionResult EditUserRole(UsersRole userRole) { try { if (ModelState.IsValid) { UsersRole roleFound = db.UsersRole.FirstOrDefault(c => c.Id == userRole.Id); if (roleFound != null) { roleFound.RoleId = userRole.RoleId; db.Entry(roleFound).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("ListUserRole", "Account")); } } catch (Exception) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persist please contact with your system administrator"); } PopulateRoleDropDownList(userRole.RoleId); return(View(userRole)); }
public UsersRole AddUserToRole(User user, Role role) { if (user == null) { throw new ArgumentNullException("user"); } if (role == null) { throw new ArgumentNullException("role"); } var userRole = (from ur in this.db.UsersRoles where ur.UserID == user.UserID where ur.RoleID == role.RoleID select ur).SingleOrDefault(); if (userRole == null) { userRole = new UsersRole { UserID = user.UserID, RoleID = role.RoleID }; this.db.UsersRoles.InsertOnSubmit(userRole); this.db.SubmitChanges(); this.InvalidateUserRoles(user.UserID); } return(userRole); }
public List <UsersRole> GetRoles() { List <UsersRole> roles = new List <UsersRole>(); UsersRole rol = new UsersRole() { Id = 1, RoleName = "Adnin", CreatedOn = DateTime.Now, CreatedBy = 1, ModifyBy = 1, ModifyOn = DateTime.Now }; UsersRole rol1 = new UsersRole() { Id = 2, RoleName = "SuperUser", CreatedOn = DateTime.Now, CreatedBy = 1, ModifyBy = 1, ModifyOn = DateTime.Now }; roles.Add(rol); roles.Add(rol1); return(roles); }
public ActionResult ActivateTheUser(int?Id) { try { using (var context = new JustHallAtumationEntities()) { var result = context.RegistrationForms.Where(x => x.RegistrationId == (int)Id).FirstOrDefault(); int id = loginRegistrationOperation.Registrataion(result); if (id > 0) { UsersRole user = new UsersRole { UserId = id, Role = "Student" }; result.IsVerified = 1; context.UsersRoles.Add(user); context.SaveChanges(); ViewBag.Success = "Successfully Activated The User!"; } else { ViewBag.Success = "Failed to Verified The user!"; } return(RedirectToAction("Notices", "Home")); } } catch (Exception ex) { return(View(ex)); } }
public ActionResult RoleAssign(UsersRole roleassign) { try { if (ModelState.IsValid) { db.UsersRole.Add(roleassign); db.SaveChanges(); return(RedirectToAction("ListUserRole")); } } catch (Exception) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persist please contact with your system administrator"); } //FLM_ROLE role = RoleRepository.roles.FirstOrDefault(c => c.role_id == roleassign.role_id); PopulateRoleDropDownList(roleassign.RoleId); PopulateUserDropDownList(roleassign.UserId); //context.SaveChanges(); return(View(roleassign)); //return RedirectToAction("ListUserRole", "Account"); }
public UsersRole AddRoles(UsersRole request) { UsersRole role = new UsersRole(); if (request.Id == 0) { role.RoleName = request.RoleName; role.CreatedOn = DateTime.Now; role.ModifyOn = DateTime.Now; role.CreatedBy = 1; role.ModifyBy = 1; _CodeFirstDataContext.UserRoles.Add(role); } else { role = _CodeFirstDataContext.UserRoles.SingleOrDefault(x => x.Id == request.Id); role.RoleName = request.RoleName; role.CreatedOn = DateTime.Now; role.ModifyOn = DateTime.Now; role.CreatedBy = 1; role.ModifyBy = 1; _CodeFirstDataContext.Entry(role).State = System.Data.EntityState.Modified; } Save(); return(role); }
private ICollection <UsersRole> GetCollectionRoles(int id) { const string SQL_EXPRESSION = "GetListRolesOfUser"; var userRoles = new List <UsersRole>(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(SQL_EXPRESSION, connection) { CommandType = System.Data.CommandType.StoredProcedure }) { _procForUser.AddUserId(command, id); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { var userRole = new UsersRole(); while (reader.Read()) { userRole.RoleId = reader.GetInt32(ROLE_ID); userRoles.Add(userRole); } } } } return(userRoles); }
public void DeleteRole(UsersRole request) { UsersRole role = _CodeFirstDataContext.UserRoles.SingleOrDefault(x => x.Id == request.Id); _CodeFirstDataContext.UserRoles.Remove(role); Save(); }
public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } //// This doen't count login failures towards lockout only two factor authentication //// To enable password failures to trigger lockout, change to shouldLockout: true //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); //switch (result) //{ // case SignInStatus.Success: // return RedirectToLocal(returnUrl); // case SignInStatus.LockedOut: // return View("Lockout"); // case SignInStatus.RequiresVerification: // return RedirectToAction("SendCode", new { ReturnUrl = returnUrl }); // case SignInStatus.Failure: // default: // ModelState.AddModelError("", "Invalid login attempt."); // return View(model); //} //string str = encryptionDecryptionUtil.CreatePasswordHash("lodi", "91qkmxU="); List <User> appusers = db.User.ToList(); foreach (var appuser in appusers) { if (appuser.UserName.Equals(model.UserName) && encryptionDecryptionUtil.VerifyPassword(appuser.Password, model.Password, appuser.Salt)) { FormsAuthentication.SetAuthCookie(model.UserName, false); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { UsersRole userpermission = db.UsersRole.First(u => u.UserId == appuser.Id); if (userpermission == null) { FormsAuthentication.SignOut(); return(RedirectToAction("AccessDenied", "Error", null)); } appuser.LastLogin = DateTime.Now; db.Entry(appuser).State = EntityState.Modified; db.SaveChanges(); //return RedirectToAction("Index", "Home"); return(RedirectToAction("Index", "Home")); } } } ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); }
private OracleParameter[] createParamList(UsersRole p) { OracleParameter[] paramsList = new OracleParameter[3]; paramsList[0] = DBHelper.mp("USER_ID", p.UserId); paramsList[1] = DBHelper.mp("ROLE_ID", p.RoleId); paramsList[2] = DBHelper.mp("ACTIVE", p.Active); return(paramsList); }
public async Task <IHttpActionResult> UpdateGroupAsync(int id, GroupModel groupUpdate) { if (id != groupUpdate.Id) { return(BadRequest()); } using (var context = new ApplicationDbContext()) { var group = await context.UserGroups.FirstOrDefaultAsync(x => x.GroupId == id); if (group == null) { return(NotFound()); } group.Name = groupUpdate.Name; group.NotifyMethodId = groupUpdate.NotifyMethodId == GlobalConstants.IsNull ? null : groupUpdate.NotifyMethodId; group.NotifyDelayDays = groupUpdate.NotifyMethodId == GlobalConstants.IsNull ? null : groupUpdate.NotifyDelayDays; foreach (var userRole in group.Roles.ToList()) { group.Roles.Remove(userRole); } if (groupUpdate.UserRoles != null && groupUpdate.UserRoles.Count != 0) { foreach (var roleName in groupUpdate.UserRoles) { string rn = roleName; var role = await context.Roles.SingleOrDefaultAsync(x => x.Name == rn); if (role != null) { group.Roles.Add(role); } } } foreach (User user in group.Users) { user.Roles.Clear(); foreach (UserRole role in group.Roles) { var usersRole = new UsersRole { UserId = user.Id, RoleId = role.Id }; user.Roles.Add(usersRole); } } await context.SaveChangesAsync(); } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Initializes a new instance of the <see cref="UsersController"/> class. /// </summary> /// <param name="context">The context<see cref="ApplicationDbContext"/></param> /// <param name="userManager">The userManager<see cref="UserManager{ApplicationUser}"/></param> /// <param name="roleManager">The roleManager<see cref="RoleManager{IdentityRole}"/></param> public UsersController(ApplicationDbContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) { _context = context; _userManager = userManager; _roleManager = roleManager; _usersRole = new UsersRole(); usuarioRole = new List <SelectListItem>(); }
public bool ChangeRole(User user, int roleId) { var role = _unitOfWork.Role.Query.FirstOrDefault(r => r.Id == roleId); var userRole = new UsersRole { UserId = user.Id, RoleId = roleId, Role = role, User = user }; _unitOfWork.UsersRole.Add(userRole); return(_unitOfWork.SaveChanges()); }
public void Create(Entities.User obj) { // transaction scope using (var trans = new System.Transactions.TransactionScope()) { // insert into Users Insert(obj); // UsersRole object Entities.UsersRole objUsersRole = new UsersRole(); objUsersRole.RoleId = obj.RoleId; objUsersRole.Uid = obj.Uid; // insert into UsersRole Rent.Business.Services.UserRole userRole = new UserRole(); userRole.Insert(objUsersRole); // UsersPassword object Entities.UsersPassword objUsersPassword = new Entities.UsersPassword(); objUsersPassword.Uid = obj.Uid; objUsersPassword.Password = obj.UsersPassword.Password; // insert into UsersPassword Rent.Business.Services.UsersPassword usersPassword = new UsersPassword(); usersPassword.Insert(objUsersPassword); // UsersNotification object Entities.UsersNotification objUsersNotification = new UsersNotification(); objUsersNotification.Uid = obj.Uid; // insert into UsersNotification Rent.Business.Services.UserNotification userNotification = new UserNotification(); userNotification.Insert(objUsersNotification); // into into UserAccessCode Rent.Business.Interfaces.IUserAccess iUserAccess = new UserAcess(); iUserAccess.Insert(Rent.Common.Helper.Generator.AccessCode(), obj.Uid); // UsersManager if (obj.ManagerId > 0) { Rent.Entities.UsersManager objUsersManager = new UsersManager(); objUsersManager.ManagerId = (int)obj.ManagerId; objUsersManager.Uid = obj.Uid; // into into UsersUsersManager Rent.Business.Interfaces.IUserManager iUserManager = new UserManager(); iUserManager.Insert(objUsersManager); } // commit transaction trans.Complete(); } }
public ActionResult Registraion(AdminRegistraionModel model) { try { if (ModelState.IsValid) { using (var context = new JustHallAtumationEntities()) { var regPass = context.AdminRegistrionPasswords.Where(x => x.AdminRegPass.Length > 0).FirstOrDefault(); string RegPass = "******"; if (regPass != null) { RegPass = regPass.AdminRegPass; } if (model.RegistraionPassword.Replace(" ", "") == RegPass.Replace(" ", "")) { var user1 = context.Users.Where(x => x.UserName.Replace(" ", "") == model.UserName.Replace(" ", "") || x.UserEmail.Replace(" ", "") == model.Email.Replace(" ", "")).FirstOrDefault(); if (user1 == null) { User user = new User() { UserName = model.UserName, UserEmail = model.Email, Password = loginRegistrationOperation.HashFunction(model.Password) }; context.Users.Add(user); UsersRole usersRole = new UsersRole() { Role = "Admin", UserId = user.UserId }; context.UsersRoles.Add(usersRole); context.SaveChanges(); ViewBag.Success = "Registraion Completed!"; } else { ViewBag.Success = "User Name or User Email allready exist"; } } else { ViewBag.Success = "Registraion Password is not currect"; } } } return(View()); } catch (Exception ex) { return(View(ex)); } }
public UsersRole getStoredUserPermission() { string username = FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; User appuser = db.User.SingleOrDefault(u => u.UserName.Equals(username, StringComparison.OrdinalIgnoreCase)); try { UsersRole userpermission = db.UsersRole.SingleOrDefault(u => u.UserId == appuser.Id); return(userpermission); } catch (NullReferenceException exp) { return(null); } }
public ArrayList Select(string p) { DataTable dt = DBHelper.SelectDataTable(UsersRole.SELECT_USERS_ROLE, DBHelper.mp("USER_ID", p)); ArrayList q = new ArrayList(); for (int i = 0; i < dt.Rows.Count; i++) { UsersRole ur = new UsersRole(); ur.UserId = (((DataRow)(dt.Rows[i]))["USER_ID"]).ToString(); ur.RoleId = (((DataRow)(dt.Rows[i]))["ROLE_ID"]).ToString(); ur.Active = (((DataRow)(dt.Rows[i]))["ACTIVE"]).ToString(); q.Add(ur); } return(q); }
public JsonResult DeleteRole(UsersRole roles) { try { UsersRole request = new UsersRole(); request.Id = roles.Id; _adminRepositoryService.DeleteRole(request); ViewData["message"] = CommonConstrant.Delete; } catch (Exception ex) { ViewData["message"] = ex.Message; } return(Json(roles, JsonRequestBehavior.AllowGet)); }
public void AddUserAccount(UserSignUpView user) { string baseUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority); using (PetrissEntities db = new PetrissEntities()) { User _user = new User(); _user.EmailId = user.EmailAddress; _user.PreferredName = user.PrefferedName; _user.Password = user.Password; _user.UserActivationLink = baseUrl + Guid.NewGuid(); _user.CreatedByUserId = user.UserId > 0 ? user.UserId : 1; _user.ModifiedByUserId = user.UserId > 0 ? user.UserId : 1;; _user.CreatedDateTime = DateTime.Now; _user.ModifiedDateTime = DateTime.Now; db.Users.Add(_user); db.SaveChanges(); UsersProfile _userprofiles = new UsersProfile(); _userprofiles.UserId = _user.UserId; _userprofiles.PreferredName = user.PrefferedName; _userprofiles.FirstName = user.FirstName; _userprofiles.LastName = user.LastName; _userprofiles.CreatedByUserId = user.UserId > 0 ? user.UserId : 1; _userprofiles.ModifiedByUserId = user.UserId > 0 ? user.UserId : 1; _userprofiles.CreatedDateTime = DateTime.Now; _userprofiles.ModifiedDateTime = DateTime.Now; db.UsersProfiles.Add(_userprofiles); db.SaveChanges(); if (user.UserLookupRoleId > 0) { UsersRole _usersrole = new UsersRole(); _usersrole.UserLookupRoleId = user.UserLookupRoleId; _usersrole.UserId = user.UserId; _usersrole.IsActive = true; _usersrole.CreatedByUserId = user.UserId > 0 ? user.UserId : 1; _usersrole.ModifiedByUserId = user.UserId > 0 ? user.UserId : 1; _usersrole.CreatedDateTime = DateTime.Now; _usersrole.ModifiedDateTime = DateTime.Now; db.UsersRoles.Add(_usersrole); db.SaveChanges(); } } }
public ActionResult UersRole(UsersRole roles) { try { UsersRole request = new UsersRole(); request.RoleName = roles.RoleName; request.Id = roles.Id; _adminRepositoryService.AddRoles(request); ViewData["message"] = CommonConstrant.save; } catch (Exception ex) { ViewData["message"] = ex.Message; } return(View(roles)); }
public List <UsersRole> LoadUsers() { List <UsersRole> us = new List <UsersRole>(); List <ref_user_SelectAll_Result> sr = new List <ref_user_SelectAll_Result>(); sr = pEntity.ref_user_SelectAll().ToList(); foreach (ref_user_SelectAll_Result p in sr) { UsersRole usr = new UsersRole(); usr.userid = p.userid; usr.Fullname = p.Fullname; usr.username = p.username; usr.password = p.password; usr.isActive = p.isActive; usr.position = p.position; us.Add(usr); } return(us); }
public int UserRoleId(string UserName) { using (var context = new JustHallAtumationEntities()) { var user = context.Users.Where(x => x.UserName.Replace(" ", "") == UserName.Replace(" ", "")).FirstOrDefault(); if (user != null) { UsersRole usersRole = new UsersRole() { Role = "MealAdmin", UserId = user.UserId }; context.UsersRoles.Add(usersRole); context.SaveChanges(); return(usersRole.Id); } } return(-1); }
public JsonResult DeleteUserRole(int id) { //string result = ""; bool flag = false; try { UsersRole roleFound = db.UsersRole.Find(id); db.UsersRole.Remove(roleFound); db.SaveChanges(); flag = true; } catch (Exception ex) { } return(Json(flag, JsonRequestBehavior.AllowGet)); }
/// <summary> /// /// </summary> /// <param name="user"></param> public void AddVendor(UserSignUpView user) { using (PetrissEntities db = new PetrissEntities()) { User _user = new User(); _user.EmailId = user.EmailAddress; _user.Password = user.Password; _user.CreatedByUserId = user.UserId > 0 ? user.UserId : 1; _user.ModifiedByUserId = user.UserId > 0 ? user.UserId : 1;; _user.CreatedDateTime = DateTime.Now; _user.ModifiedDateTime = DateTime.Now; db.Users.Add(_user); db.SaveChanges(); UsersProfile _userprofiles = new UsersProfile(); _userprofiles.UserId = _user.UserId; _userprofiles.FirstName = user.FirstName; _userprofiles.LastName = user.LastName; _userprofiles.CreatedByUserId = user.UserId > 0 ? user.UserId : 1; _userprofiles.ModifiedByUserId = user.UserId > 0 ? user.UserId : 1; _userprofiles.CreatedDateTime = DateTime.Now; _userprofiles.ModifiedDateTime = DateTime.Now; db.UsersProfiles.Add(_userprofiles); db.SaveChanges(); if (user.UserLookupRoleId > 0) { UsersRole _usersrole = new UsersRole(); _usersrole.UserLookupRoleId = user.UserLookupRoleId; _usersrole.UserId = user.UserId; _usersrole.IsActive = true; _usersrole.CreatedByUserId = user.UserId > 0 ? user.UserId : 1; _usersrole.ModifiedByUserId = user.UserId > 0 ? user.UserId : 1; _usersrole.CreatedDateTime = DateTime.Now; _usersrole.ModifiedDateTime = DateTime.Now; db.UsersRoles.Add(_usersrole); db.SaveChanges(); } } }
public UserManagerViewPage Index(string searchString, UsersRole Role, int?page) { UserManagerViewPage xx = new UserManagerViewPage(); var Users = db.UsersInfo.Where(s => s.UserRole != UsersRole.SystemManager).ToList(); int pageNumber; int pageSizeNum; int ItemNum; int pageNum; if (Role == UsersRole.All) { Users = Users.Where(s => s.UserName.Contains(searchString)).ToList(); } else { if (!String.IsNullOrEmpty(searchString)) { Users = Users.Where(s => s.UserName.Contains(searchString)).ToList(); } Users = Users.Where(s => s.UserRole == Role).ToList(); } pageSizeNum = 5; //每页显示多少条 ItemNum = Users.Count(); //数据总数 pageNum = (ItemNum % pageSizeNum) == 0 ? (ItemNum / pageSizeNum) : (ItemNum / pageSizeNum) + 1; //总页数 if (page == 4) { pageNumber = pageNum; } else { pageNumber = page ?? 1; } Users = Users.OrderBy(x => x.UserID).Skip((pageNumber - 1) * pageSizeNum).Take(pageSizeNum).ToList(); xx.aa = Users; xx.pageNumber = pageNumber; xx.pageNumx = pageNum; xx.ItemNum = ItemNum.ToString(); xx.searchstring = searchString; xx.Role = Role; return(xx); }
public bool addUser(UsersRole usr) { bool rtval = false; try { pEntity.ref_user_Insert(usr.userid, usr.username, usr.password, usr.isActive, usr.Fullname, usr.position); pEntity.SaveChanges(); rtval = true; } catch (Exception ex) { _err = ex.ToString(); a.logModule = "User CS"; a.logError = ex.ToString(); a.DateCreated = DateTime.Now; lg.InsertLog(a); rtval = false; } return(rtval); }
public ActionResult UserLogin(UserLogin login) { IAdminRepositoryService _adminRepositoryService = new AdminRepositoryService(); UsersInfo info = _adminRepositoryService.UserAuthentication(login); if (info != null) { UsersRole role = _adminRepositoryService.GetRoleByRoleId(Convert.ToInt32(info.RoleId)); if (role.RoleName.Equals("SuperUser") || role.RoleName.Equals("Admin")) { Session["RoleName"] = role.RoleName; Session["RoleId"] = info.UserId; CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.UserId = info.UserId; serializeModel.UserName = info.UserName; serializeModel.roles = new string[] { role.RoleName }; string userData = JsonConvert.SerializeObject(serializeModel); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, info.UserName, DateTime.Now, DateTime.Now.AddMinutes(5), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); return(RedirectToAction("Index", "Admin")); } } return(View()); }
public UsersRole AddRoles(UsersRole request) { return(_adminRepositoryService.AddRoles(request)); }