/// <summary> /// 增加快捷键 /// </summary> /// <param name="newShortcut">页面传回的新增快捷键对象</param> public void AddShortcut(MemberUserShortcut newShortcut) { if (base.GetProgramNode("EnableEdit") == "1") { Guid userID = GetUserID(); //查找用户曾使用过、但被删除的快捷键 MemberUserShortcut oldShortcut = dbEntity.MemberUserShortcuts.Include("Program").Where(o => o.ProgID == newShortcut.ProgID && o.UserID == userID).SingleOrDefault(); //如果存在,则将Delete设回false并更新,如果不存在,则保存一个新的MemberUserShortcut对象 if (oldShortcut != null) { oldShortcut.Deleted = false; oldShortcut.Sorting = newShortcut.Sorting; oldShortcut.Icon = newShortcut.Icon; oldShortcut.ProgID = newShortcut.ProgID; oldShortcut.Remark = newShortcut.Remark; if (ModelState.IsValid) { dbEntity.Entry(oldShortcut).State = EntityState.Modified; dbEntity.SaveChanges(); } } else { newShortcut.UserID = userID; if (newShortcut.ProgID == null) //判断传回的SType是URL还是Program { newShortcut.Stype = 1; dbEntity.MemberUserShortcuts.Add(newShortcut); dbEntity.SaveChanges(); } else { newShortcut.Stype = 0; dbEntity.MemberUserShortcuts.Add(newShortcut); dbEntity.SaveChanges(); } } } }
/// <summary> /// 编辑用户快捷键 /// </summary> /// <param name="newShortcut"></param> /// <returns></returns> public void SaveEditShortcut(MemberUserShortcut newShortcut) { if (base.GetProgramNode("EnableEdit") == "1") { MemberUserShortcut oldShortcut = dbEntity.MemberUserShortcuts.Include("Program").Where(g => g.Gid == newShortcut.Gid).Single(); if (newShortcut.Icon != null) { oldShortcut.LinkUrl = newShortcut.LinkUrl; } if (newShortcut.ProgID != Guid.Empty) { oldShortcut.ProgID = newShortcut.ProgID; } oldShortcut.Deleted = false; oldShortcut.Sorting = newShortcut.Sorting; oldShortcut.Icon = newShortcut.Icon; oldShortcut.Remark = newShortcut.Remark; if (ModelState.IsValid) { dbEntity.Entry(oldShortcut).State = EntityState.Modified; dbEntity.SaveChanges(); } } }