public void UpdateUser(User user) { try { var existingUser = DB.Users.First(u => u.ID == user.ID); existingUser.Password = user.Password; existingUser.FirstName = user.FirstName; existingUser.LastName = user.LastName; existingUser.DisplayName = user.DisplayName; existingUser.Job = user.Job; existingUser.Email = user.Email; existingUser.IM = user.IM; existingUser.Skype = user.Skype; existingUser.Phone = user.Phone; existingUser.Photo = user.Photo; existingUser.GroupID = user.GroupID; existingUser.LastModifiedByUserID = user.LastModifiedByUserID; existingUser.LastModifiedOnDate = user.LastModifiedOnDate; } catch (Exception) { throw new Exception("Lỗi cập nhật thông tin người dùng"); } }
public void AddUser(User user) { try { DB.AddToUsers(user); } catch (Exception) { throw new Exception("Lỗi thêm người dùng"); } }
public ActionResult Setup(AccountModel model, HttpPostedFileBase file) { try { if (!ModelState.IsValid) { return View(model); } // tạo ra admin mới var newUser = new User { UserName = model.UserName, Password = Encrypt(model.Password), Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, Job = model.Job, IM = model.YahooID, Skype = model.SkypeID, Phone = model.Phone, GroupID = 1, // set to administrator group CreatedOnDate = DateTime.Now }; if (file != null) { if (file.ContentLength > 26214400) { return RedirectToAction("Error", new { eID = 6 }); } var dir = root + file.FileName; var ext = Path.GetExtension(file.FileName); if (!System.IO.File.Exists(dir)) { newUser.Photo = newUser.UserName + ext; file.SaveAs(dir); System.IO.File.Move(dir, root + newUser.UserName + ext); } else { return RedirectToAction("Error", new { eID = 7 }); } } _repository.AddUser(newUser); _repository.CommitChanges(); return RedirectToLogin(); } catch (Exception) { return RedirectToAction("Error", new { eID = 0 }); } }
public ActionResult Register(AccountModel model, HttpPostedFileBase file) { try { if (!ModelState.IsValid) { return RedirectToAction("Error", "Base", new { eID = 0 }); } var user = _repository.FindUserByUserName(model.UserName); if (user != null) { return RedirectToAction("Error", "Base", new { eID = 2 }); } string email = _repository.FindEmail(model.Email); if (!string.IsNullOrEmpty(email)) { return RedirectToAction("Error", "Base", new { eID = 3 }); } var newUser = new User { UserName = model.UserName, Password = Encrypt(model.Password), Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, Job = model.Job, IM = model.YahooID, Skype = model.SkypeID, Phone = model.Phone, GroupID = model.GroupID, CreatedByUserID = int.Parse(User.Identity.Name), CreatedOnDate = DateTime.Now }; if (file != null) { if (file.ContentLength > 26214400) { return RedirectToAction("Error", new { eID = 6 }); } var dir = root + file.FileName; var ext = Path.GetExtension(file.FileName); if (!System.IO.File.Exists(dir)) { newUser.Photo = newUser.UserName + ext; file.SaveAs(dir); System.IO.File.Move(dir, root + newUser.UserName + ext); } else { return RedirectToAction("Error", new { eID = 7 }); } } _repository.AddUser(newUser); _repository.CommitChanges(); return RedirectToAction("Group", "User", new { groupID = model.GroupID }); } catch (Exception) { return RedirectToAction("Error", new { eID = 0 }); } }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
/// <summary> /// Create a new User object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="userName">Initial value of the UserName property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="displayName">Initial value of the DisplayName property.</param> /// <param name="groupID">Initial value of the GroupID property.</param> public static User CreateUser(global::System.Int32 id, global::System.String userName, global::System.String password, global::System.String firstName, global::System.String lastName, global::System.String displayName, global::System.Int32 groupID) { User user = new User(); user.ID = id; user.UserName = userName; user.Password = password; user.FirstName = firstName; user.LastName = lastName; user.DisplayName = displayName; user.GroupID = groupID; return user; }