/// <summary> /// The create. /// </summary> /// <param name="author"> /// The author. /// </param> /// <returns> /// The LiteBlog.BlogEngine.EngineException. /// </returns> public static EngineException Create(Author author) { MembershipUser user = Membership.GetUser(author.ID); if (user != null) { EngineException ex = new EngineException("Author with the same user name already exists"); return ex; } try { user = Membership.CreateUser(author.ID, ConfigHelper.DefaultPassword, author.Email); if (user != null) { ProfileComp.SetDisplayName(author.ID, author.Name); } } catch (Exception inner) { EngineException ex = new EngineException("Creating a new user failed", inner); return ex; } return null; }
public ActionResult Create(AuthorModel model) { if (this.ModelState.IsValid) { // Edit Author Author author = new Author(); author.ID = model.Name; author.Name = model.DisplayName; author.Email = model.Email; EngineException ex = AuthorComp.Create(author); if (ex != null) { this.ModelState.AddModelError("Create", ex); } } if (this.ModelState.IsValid) { this.TempData["Message"] = "用户添加成功"; return this.RedirectToAction("Manage"); } this.ViewData.Model = model; return this.View(); }
/// <summary> /// ID should be the same for update to work /// </summary> /// <param name="oldID"> /// The old ID. /// </param> /// <param name="author"> /// The author /// </param> /// <returns> /// The LiteBlog.BlogEngine.EngineException. /// </returns> public static EngineException Update(string oldID, Author author) { if (author.ID != oldID) { // change the author ID (lot of checks) MembershipUser user = Membership.GetUser(author.ID); if (user != null) { EngineException ex = new EngineException("Another author has the same username"); return ex; } else { // Get password MembershipUser oldUser = Membership.GetUser(oldID); string password = oldUser.GetPassword(); try { user = Membership.CreateUser(author.ID, password, author.Email); Membership.DeleteUser(oldID); if (user != null) { foreach (PostInfo postInfo in BlogComp.GetPostsByAuthor(oldID)) { BlogComp.ChangeAuthor(postInfo.FileID, user.UserName); PostComp.ChangeAuthor(postInfo.FileID, user.UserName); } } } catch (Exception inner) { EngineException ex = new EngineException("Updating the author details failed", inner); return ex; } } } else { try { MembershipUser user = Membership.GetUser(author.ID); if (user != null) { user.Email = author.Email; Membership.UpdateUser(user); } } catch (Exception inner) { EngineException ex = new EngineException("Updating the author details failed", inner); return ex; } } ProfileComp.SetDisplayName(author.ID, author.Name); return null; }
/// <summary> /// The get authors. /// </summary> /// <returns> /// The System.Collections.Generic.List`1[T -> LiteBlog.Common.Author]. /// </returns> public static List<Author> GetAuthors() { List<Author> authors = new List<Author>(); foreach (MembershipUser user in Membership.GetAllUsers()) { Author author = new Author(); author.ID = user.UserName; author.Email = user.Email; author.Locked = user.IsLockedOut; author.Name = ProfileComp.GetDisplayName(author.ID); authors.Add(author); } return authors; }
public ActionResult Edit(AuthorModel model) { if (this.ModelState.IsValid) { // Edit Author string oldName = this.TempData["AuthorName"].ToString(); Author author = new Author(); author.ID = model.Name; author.Name = model.DisplayName; author.Email = model.Email; EngineException ex = AuthorComp.Update(oldName, author); if (ex != null) { this.ModelState.AddModelError("Edit", ex); } } if (this.ModelState.IsValid) { this.TempData["Message"] = "用户信息已更新"; return this.RedirectToAction("Manage"); } this.ViewData.Model = model; return this.View(); }