/// <summary> /// The create user. /// </summary> /// <param name="user"> /// The user. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public int CreateUser(NewUser user) { var createcontext = new ScrumNotesDbClassDataContext( ConfigurationManager.ConnectionStrings["ScrumNotesCombinerConnectionString"].ToString()); int users = (from u in createcontext.Users where u.ADUserName.Equals(user.ADname) select u).Count(); try { if (users != 0) { return 2; } int newid = createcontext.Users.Count() + 1; var record = new User { Id = newid, ADUserName = user.ADname, Allias = user.Name, Email = user.Email, Comments = user.Comments }; createcontext.Users.InsertOnSubmit(record); createcontext.Users.Context.SubmitChanges(); createcontext.Dispose(); return 0; } catch (Exception e) { return 1; } }
public ActionResult ActionWithUser(int id, string UserAction) { // Performes actions with users var nuser = new NewUser(); var ScrumNotesDatabase = new Database(); nuser.UserAction = UserAction; switch (UserAction) { case "Create": nuser.AllowEdit = true; return View(nuser); case "View": nuser.AllowEdit = false; nuser = ScrumNotesDatabase.GetUserInfo(id); return this.View(nuser); case "Edit": nuser = ScrumNotesDatabase.GetUserInfo(id); nuser.id = id; nuser.AllowEdit = true; return this.View(nuser); case "Delete": ScrumNotesDatabase.DeleteUser(id); return this.RedirectToAction("ShowUsers"); } return this.View(); }
public ActionResult ActionWithUser(NewUser newUser) { var ScrumNotesDatabase = new Database(); switch (newUser.UserAction) { case "Create": ScrumNotesDatabase.CreateUser(newUser); return this.RedirectToAction("ShowUsers"); case "Edit": ScrumNotesDatabase.ModifyUser(newUser); return this.RedirectToAction("ShowUsers"); } return this.View(newUser); }
/// <summary> /// The modify user. /// </summary> /// <param name="user"> /// The user. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool ModifyUser(NewUser user) { try { var modifycontext = new ScrumNotesDbClassDataContext( ConfigurationManager.ConnectionStrings["ScrumNotesCombinerConnectionString"].ToString()); User userrecord = (from u in modifycontext.Users where u.Id.Equals(user.id) select u).Single(); userrecord.Allias = user.Name; userrecord.ADUserName = user.ADname; userrecord.Comments = user.Comments; userrecord.Email = user.Email; userrecord.ScrumAdmin = user.IsSCRUMadmin ?? false; modifycontext.SubmitChanges(); modifycontext.Dispose(); return true; } catch (Exception e) { return false; } }
/// <summary> /// The get user info. /// </summary> /// <param name="userId"> /// The user id. /// </param> /// <returns> /// The <see cref="NewUser"/>. /// </returns> public NewUser GetUserInfo(int userId) { var selectioncontext = new ScrumNotesDbClassDataContext( ConfigurationManager.ConnectionStrings["ScrumNotesCombinerConnectionString"].ToString()); var user = new NewUser(); IQueryable<User> selectuser = from u in selectioncontext.Users where u.Id.Equals(userId) select u; user.Name = selectuser.FirstOrDefault().Allias; user.ADname = selectuser.FirstOrDefault().ADUserName; user.IsSCRUMadmin = selectuser.FirstOrDefault().ScrumAdmin; user.Email = selectuser.FirstOrDefault().Email; user.Comments = selectuser.FirstOrDefault().Comments; selectioncontext.Dispose(); return user; }