/// <summary> /// 是否将上传了附件笔记 /// </summary> /// <param name="noteId"></param> public void CreateAttachment(int noteId) { var note = CurrentDB.OneNoteTable.Find(noteId); note.WithAttach = true; CurrentDB.SaveChanges(); }
/// <summary> /// 物理删除笔记 /// </summary> /// <param name="noteId"></param> public void RemoveNoteFinal(int noteId) { var note = GetMyNote(noteId); CurrentDB.OneNoteTable.Remove(note); CurrentDB.SaveChanges(); }
public void Delete(int planId) { var plan = CurrentDB.DayPlanTable.Find(planId); CurrentDB.DayPlanTable.Remove(plan); CurrentDB.SaveChanges(); }
/// <summary> /// 更新笔记本 /// </summary> /// <param name="bookId"></param> /// <param name="bookName"></param> /// <returns></returns> public NoteBook UpdateNoteBook(int bookId, string bookName) { var notebook = GetMyBook(bookId); notebook.BookName = bookName; CurrentDB.SaveChanges(); return(notebook); }
/// <summary> /// 增加一条笔记 /// </summary> /// <param name="note"></param> /// <returns></returns> public OneNote CreateNote(NewNote note) { var oneNote = (OneNote)note; oneNote.UserId = CurrentPrincipal.UserId; CurrentDB.OneNoteTable.Add(oneNote); CurrentDB.SaveChanges(); return(note); }
public DayPlan Update(int planId, string content, DateTime endAt) { var plan = CurrentDB.DayPlanTable.Find(planId); plan.Content = content; plan.CreateAt = endAt; CurrentDB.SaveChanges(); return(plan); }
/// <summary> /// 修改1条笔记 /// </summary> /// <param name="noteId"></param> /// <param name="oneNote"></param> /// <returns></returns> public OneNote UpdateNote(NoteUpdating noteUpdating) { var oneNote = GetMyNote(noteUpdating.NoteId); if (oneNote == null) { throw new ArgumentException("笔记未找到"); } noteUpdating.Merge(oneNote).UpdateAt = DateTime.Now; CurrentDB.SaveChanges(); return(oneNote); }
public bool ToggleShareOrNot(int planId) { var plan = CreateMyQuery().FirstOrDefault(o => o.Id == planId); if (plan != null) { plan.ShareOrNot = !plan.ShareOrNot; CurrentDB.SaveChanges(); return(plan.ShareOrNot); } return(false); }
public bool ToggleShareIt(int noteId) { var note = GetMyNote(noteId); if (note != null) { note.ShareOrNot = !note.ShareOrNot; CurrentDB.SaveChanges(); return(note.ShareOrNot); } return(false); }
public DayPlan Create(PlanType type, long UserId, DateTime StartAt) { DayPlan dayplan = new DayPlan() { UserId = CurrentPrincipal.UserId, CreateAt = DateTime.Now, UpdateAt = DateTime.Now }; CurrentDB.DayPlanTable.Add(dayplan); CurrentDB.SaveChanges(); return(dayplan); }
public bool ToggleCompleted(int planId) { var plan = CreateMyQuery().FirstOrDefault(o => o.Id == planId); if (plan != null) { plan.IsCompleted = !plan.IsCompleted; plan.CompletedAt = plan.IsCompleted ? new DateTime?(DateTime.Now) : null; CurrentDB.SaveChanges(); return(plan.IsCompleted); } return(false); }
public bool DeletePlan(int planId) { var plan = CreateMyQuery().FirstOrDefault(o => o.Id == planId); if (plan == null) { return(false); } CurrentDB.DayPlanTable.Remove(plan); CurrentDB.SaveChanges(); return(true); }
/// <summary> /// 撤销删除的笔记 /// </summary> /// <param name="noteId"></param> /// <returns></returns> public bool RecoveryNote(int noteId) { var onenote = GetMyNote(noteId, true); if (onenote == null) { return(false); } onenote.IsDeleted = false; CurrentDB.SaveChanges(); return(!onenote.IsDeleted); }
private ShareList CreateShareList(int?noteId = null, int?planId = null) { var shareInfo = CurrentDB.ShareTable.Add(new ShareList() { UserId = AuthorizationContext.CurrentPrincipal.UserId, ShareAt = DateTime.Now, PlanId = planId, NoteId = noteId }); CurrentDB.SaveChanges(); return(shareInfo); }
public DayPlan UpdatePlan(PlanUpdateInput updating) { var plan = CreateMyQuery().FirstOrDefault(o => o.Id == updating.PlanId); if (plan == null) { return(null); } plan = updating.UpdateTo(plan); CurrentDB.SaveChanges(); return(plan); }
/// <summary> /// 删除笔记本 /// </summary> /// <param name="bookId"></param> public void RemoveNoteBook(int bookId) // OK { var notebook = GetMyBook(bookId); if (notebook != null) { var notes = CurrentDB.OneNoteTable.Where(o => o.BookId == bookId); CurrentDB.OneNoteTable.RemoveRange(notes); CurrentDB.NoteBookTable.Remove(notebook); CurrentDB.SaveChanges(); } }
public DayOne.Entities.DayPlan CreatePlan(PlanInput planInput) { if (planInput == null) { throw new ArgumentNullException("planInput"); } DayPlan dayplan = planInput; dayplan.UserId = this.CurrentPrincipal.UserId; dayplan = CurrentDB.DayPlanTable.Add(dayplan); CurrentDB.SaveChanges(); return(dayplan); }
public UserInfo ChangePassword(string newpw) { if (string.IsNullOrWhiteSpace(newpw)) { return(null); } var userInfo = CurrentDB.UserTable.Find(CurrentPrincipal.UserId); if (userInfo == null) { return(null); } userInfo.PassWord = newpw; CurrentDB.SaveChanges(); return(null); }
/// <summary> /// 逻辑删除 放到回收站 /// </summary> /// <param name="noteId"></param> public void RemoveNote2(int noteId, bool destroy = false) { var onenote = GetMyNote(noteId, true); if (onenote == null) { return; } if (destroy) { CurrentDB.OneNoteTable.Remove(onenote); } else { onenote.IsDeleted = true; } CurrentDB.SaveChanges(); }
/// <summary> /// 增加笔记本 /// </summary> /// <param name="bookName"></param> /// <param name="bookId"></param> /// <returns></returns> public NoteBook AddNoteBook(string bookName) // OK { if (string.IsNullOrWhiteSpace(bookName)) { throw new ArgumentNullException("bookName"); } NoteBook notebook = new NoteBook() { UserId = CurrentPrincipal.UserId, CreateAt = DateTime.Now, BookName = bookName, ShareOrNot = false, }; CurrentDB.NoteBookTable.Add(notebook); CurrentDB.SaveChanges(); return(notebook); }
public bool ToggleLoveIt(int shareId) { if (CurrentPrincipal == null) { return(false); } var userId = CurrentPrincipal.UserId; try { if (!CurrentDB.PraiseUsers.Any(o => o.ShareId == shareId && o.UserId == userId)) { CurrentDB.PraiseUsers.Add(new PraiseUser() { UserId = userId, ShareId = shareId, LikeAt = DateTime.Now }); CurrentDB.Database.ExecuteSqlCommand("UPDATE ShareInfos set LoveCount=LoveCount+1 WHERE Id=@p0", new SqlParameter("p0", shareId)); return(true); } else { CurrentDB.PraiseUsers.RemoveRange( CurrentDB.PraiseUsers.Where(o => o.ShareId == shareId && o.UserId == userId)); CurrentDB.Database.ExecuteSqlCommand("UPDATE ShareInfos set LoveCount=LoveCount-1 WHERE Id=@p0", new SqlParameter("p0", shareId)); return(false); } } finally { CurrentDB.SaveChanges(); } }
public UserInfo RegisterV1(RegisterRequest userRegister) { if (!string.Equals(userRegister.PassWord, userRegister.PassWord2)) { throw new ArgumentException("密码不匹配", "PassWord"); } var dbContext = CurrentDB; if (dbContext.UserTable.Any(o => o.UserName == userRegister.UserName)) { throw new ArgumentException("用户名已经存在", "UserName"); } var user = CurrentDB.UserTable.Add(new DayOne.Entities.UserInfo { UserName = userRegister.UserName, PassWord = userRegister.PassWord }); CurrentDB.SaveChanges(); return(user); }