public UserDto(User user) { Login = user.Login; Name = user.Name; Password = "******"; Email = user.Email; Phone = user.Phone; }
public static int UpdateUserById(User user) { try { string comText = "update [tUsers] set tUsers.uname='" + user.UName + "', tUsers.upwd='" + user.UPwd + "', tUsers.utext='" + user.UText + "', tUsers.ulevel='" + user.ULevel + "', tUsers.userupdate='" + user.UserUpdate + "' where tUsers.userid=" + user.UserId; int rlt = OleDbHelper.ExecuteNonQuery(comText); return rlt; } catch (Exception e) { throw e; } }
public static int AddUser(User user) { try { string comText = "insert into [tUsers] (uname ,upwd ,utext ,ulevel) values ( '" + user.UName + "', '" + user.UPwd + "', '" + user.UText + "', " + user.ULevel + ")"; int rlt = OleDbHelper.ExecuteNonQuery(comText); return rlt; } catch (Exception e) { throw e; } }
public void Create(UserDTO user) { User u = new User { Email = user.Email, Password = user.Password, RoleId = user.RoleId }; Database.Users.Create(u); Database.Save(); DAL.Entities.Profile prof = new DAL.Entities.Profile { FirstName = "Undefined", LastName = "Undefined", Age = 0, CreationDate = DateTime.Now, UserId = u.Id }; Database.Profiles.Create(prof); Database.Save(); }
protected void GridViewUsers_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "AddUser") { if (GridViewUsers.FooterRow != null) { DAL.Entities.User user = new User(); user.UName = (GridViewUsers.FooterRow.FindControl("TextBoxUserNameFooter") as TextBox).Text.Trim(); user.UPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile((GridViewUsers.FooterRow.FindControl("TextBoxPwdFooter") as TextBox).Text.Trim(), "MD5"); user.ULevel = Convert.ToInt32((GridViewUsers.FooterRow.FindControl("ddlUlevelFooter") as DropDownList).SelectedValue); user.UText = (GridViewUsers.FooterRow.FindControl("textBoxUtextFooter") as TextBox).Text; user.UserUpdate = DateTime.Now; try { int rlt = DalHandler.AddUser(user); if (rlt == 1) { RefreshCacheUsers(0, user); BindGridView(true); } else { //... } } catch (Exception ex) { errorPlace.InnerHtml = ex.Message; } } } else if (e.CommandName == "DeleteUser") { if (e.CommandArgument != null) { int userId = Convert.ToInt32(e.CommandArgument); try { int rlt = DalHandler.DeleteUserById(userId); if (rlt == 1) { DataTable dt = Cache["UsersCache"] as DataTable; foreach (DataRow row in dt.Rows) { if (row["userid"].ToString().Equals(userId.ToString(), StringComparison.OrdinalIgnoreCase)) { row.Delete(); break; } } BindGridView(false); } } catch (Exception ex) { errorPlace.InnerText = ex.Message; } } } }
protected void GridViewUsers_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { int rowIndex = e.RowIndex; GridViewRow row = GridViewUsers.Rows[rowIndex]; HiddenField hiddfield = row.FindControl("userIdHiddenField") as HiddenField; if (hiddfield != null && !string.IsNullOrEmpty(hiddfield.Value)) { DAL.Entities.User user = new User(); user.UserId = Convert.ToInt32(hiddfield.Value); user.UName = (row.Cells[1].Controls[1] as TextBox).Text; user.UPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile((row.Cells[2].Controls[1] as TextBox).Text, "MD5"); user.ULevel = Convert.ToInt32((row.Cells[4].Controls[1] as DropDownList).SelectedValue); user.UText = (row.Cells[3].Controls[1] as TextBox).Text; user.UserUpdate = DateTime.Now; int rlt = DalHandler.UpdateUserById(user); if (rlt == 1) { RefreshCacheUsers(rowIndex, user); GridViewUsers.EditIndex = -1; BindGridView(true); } } else { BindGridView(true); } } catch (Exception ex) { errorPlace.InnerText = ex.Message; } }
public ActionResult Login(User user) { return View(user); }