public Domain.Notepad SaveNote(Domain.Notepad mo) { mo.Uid = new Func.UserAuthAid(HttpContext).Get().UserId; if (string.IsNullOrEmpty(mo.NoteTitle)) { mo.NoteTitle = mo.NoteContent.Length > 20 ? mo.NoteContent.Substring(0, 20) : mo.NoteContent; } mo.NoteUpdateTime = DateTime.Now; using (var db = new ContextBase()) { if (mo.NoteId == 0) { mo.NoteCreateTime = mo.NoteUpdateTime; db.Notepad.Add(mo); } else { db.Notepad.Update(mo); } db.SaveChanges(); } return(mo); }
public SharedResultVM SaveNote(Domain.Notepad mo) { var vm = Apps.LoginService.CompleteInfoValid(HttpContext); if (vm.Code == 200) { if (string.IsNullOrWhiteSpace(mo.NoteTitle) || string.IsNullOrWhiteSpace(mo.NoteContent)) { vm.Set(SharedEnum.RTag.lack); } else { var uinfo = Apps.LoginService.Get(HttpContext); var now = DateTime.Now; if (mo.NoteId == 0) { mo.NoteCreateTime = now; mo.NoteUpdateTime = now; mo.Uid = uinfo.UserId; db.Notepad.Add(mo); int num = db.SaveChanges(); vm.Set(num > 0); vm.Data = mo.NoteId; } else { var currmo = db.Notepad.Find(mo.NoteId); if (currmo.Uid == uinfo.UserId) { currmo.NoteTitle = mo.NoteTitle; currmo.NoteContent = mo.NoteContent; currmo.NoteUpdateTime = now; db.Notepad.Update(currmo); int num = db.SaveChanges(); vm.Set(num > 0); } else { vm.Set(SharedEnum.RTag.unauthorized); } } } } return(vm); }
public ActionResultVM SaveNote(Domain.Notepad mo) { var vm = new ActionResultVM(); if (string.IsNullOrWhiteSpace(mo.NoteTitle) || string.IsNullOrWhiteSpace(mo.NoteContent)) { vm.Set(ARTag.lack); } else { var uinfo = new Func.UserAuthAid(HttpContext).Get(); using var db = new ContextBase(); var now = DateTime.Now; if (mo.NoteId == 0) { mo.NoteCreateTime = now; mo.NoteUpdateTime = now; mo.Uid = uinfo.UserId; db.Notepad.Add(mo); int num = db.SaveChanges(); vm.Set(num > 0); vm.data = mo.NoteId; } else { var currmo = db.Notepad.Find(mo.NoteId); if (currmo.Uid == uinfo.UserId) { currmo.NoteTitle = mo.NoteTitle; currmo.NoteContent = mo.NoteContent; currmo.NoteUpdateTime = now; db.Notepad.Update(currmo); int num = db.SaveChanges(); vm.Set(num > 0); } else { vm.Set(ARTag.unauthorized); } } } return(vm); }