//添加导航时不对排序字段进行设置,默认为0,显示在最前的位置,当第一次执行排序操作时,将会对SortIndex进行更新 public void AddNavigation(string navName, string url, string description, string parentId, bool asMenu) { using (var context = new WSI.DataAccess.WSICmsContext()) { Navigation nav = new Navigation(); nav.NavigationName = navName; nav.Url = url; nav.Description = description; nav.AsMenu = asMenu; //父导航 Guid id; if (Guid.TryParse(parentId, out id)) { nav.Parent = context.Navigations.Find(id); } nav.State = (int)EnumHelper.State.Enable; nav.CreateTime = DateTime.Now; context.Navigations.Add(nav); context.LogChangesDuringSave = true; context.SaveChanges(); } }
public void Add(string rolename, string description, IList<string> navlist) { using (var context = new WSI.DataAccess.WSICmsContext()) { RoleInfo role = new RoleInfo(); role.RoleInfoId = Guid.NewGuid(); role.RoleName = rolename; role.Description = description; role.CreateTime = DateTime.Now; //设置权限 setNavigation(context, role, navlist); //角色类型 if (SiteManager == null) { //如果没有站点管理角色 role.RoleType = (int)RoleType.SiteManager; } else { role.RoleType = (int)RoleType.Common; } context.RoleInfoes.Add(role); context.LogChangesDuringSave = true; context.SaveChanges(); } }
public int AddTag(string parentId, string tagName, string code, string description) { using (var context = new WSI.DataAccess.WSICmsContext()) { Tag tag = new Tag(); tag.TagName = tagName; tag.TagCode = code; tag.Description = description; //父标签 Guid pid; if (Guid.TryParse(parentId, out pid)) { tag.Parent = context.Tags.Find(pid); } tag.CreateTime = DateTime.Now; tag.State = (int)EnumHelper.State.Enable;//默认启用 context.Tags.Add(tag); context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public void AddAttachImage(string infoid, string path, string description) { using (var context = new WSI.DataAccess.WSICmsContext()) { var info = GetDetailIncludeAll(infoid); context.Informations.Attach(info); //var info = GetDetailIncludeAll(infoid, context); if (info.Attachments == null) { info.Attachments = new List<Attachment>(); } long sortindex = info.Attachments.Count == 0 ? 0 : (info.Attachments.Select(a => a.SortIndex).Max() + 10); info.Attachments.Add(new Attachment() { SourceUrl = path, Description = description, CreateTime = DateTime.Now, State = (int)EnumHelper.State.Disable, SortIndex = sortindex }); context.LogChangesDuringSave = true; context.SaveChanges(); } }
public bool AddSize(string sizeName, int width, int height, int thumb_width, int thumb_height, int cover_width, int cover_height, out IList<string> errors) { using (var context = new WSI.DataAccess.WSICmsContext()) { var entity = new ImageSize() { SizeName = sizeName, Width = width, Height = height, ThumbWidth = thumb_width, ThumbHeight = thumb_height, CoverWidth = cover_width, CoverHeight = cover_height, State = (int)EnumHelper.State.Enable, CreateTime = DateTime.Now }; var validate = context.Entry(entity).GetValidationResult(); if (!validate.IsValid) { errors = validate.ValidationErrors.Select(e => e.ErrorMessage).ToList(); return false; } context.ImageSizes.Add(entity); context.LogChangesDuringSave = true; context.SaveChanges(); errors = null; return true; } }
public int AddNavigation(string parentId, string navName, string url, int type, string description) { using (var context = new WSI.DataAccess.WSICmsContext()) { FrontendNavigation nav = new FrontendNavigation(); nav.NavName = navName; nav.Url = url; nav.Type = type; //添加父导航 Guid pid; if (Guid.TryParse(parentId, out pid)) { nav.Parent = context.FrontendNavigations.Find(pid); } nav.Description = description; nav.State = (int)EnumHelper.State.Enable; nav.CreateTime = DateTime.Now; context.FrontendNavigations.Add(nav); context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public void Add(JoinApply apply) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.Entry(apply).State = EntityState.Added; context.SaveChanges(); } }
public int ChangeState(RoleInfo role, int state) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.RoleInfoes.Attach(role); role.State = state; context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public int ChangeState(Attachment attach, int state) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.Attachments.Attach(attach); attach.State = state; context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public int ChangeState(UserInfo user, int state) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.UserInfoes.Attach(user); user.State = state; context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public int ChangeState(FrontendNavigation nav, int state) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.FrontendNavigations.Attach(nav); nav.State = state; context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public int ChangeState(Recruitment item, int state) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.Recruitments.Attach(item); item.State = state; context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public int Delete(string id) { using (var context = new WSI.DataAccess.WSICmsContext()) { var item = GetDetail(id); context.Entry(item).State = EntityState.Deleted; context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public int Delete(string id) { using (var context = new WSI.DataAccess.WSICmsContext()) { var nav = GetDetailIncludeAll(id); context.Navigations.Attach(nav); context.Navigations.Remove(nav); context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public void UpdateAttach(string attachId, string description, int sortIndex) { using (var context = new WSI.DataAccess.WSICmsContext()) { var attach = GetDetail(attachId); if (attach != null) { context.Attachments.Attach(attach); attach.Description = description; attach.SortIndex = sortIndex; context.LogChangesDuringSave = true; context.SaveChanges(); } } }
public int Delete(string userid) { using (var context = new WSI.DataAccess.WSICmsContext()) { var user = GetDetail(userid); context.UserInfoes.Attach(user); //加载个人信息和角色信息到内存中 context.Entry(user).Reference(u => u.Profile).Load(); context.Entry(user).Collection(u => u.RoleList).Load(); context.UserInfoes.Remove(user); context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public int Delete(string id) { using (var context = new WSI.DataAccess.WSICmsContext()) { //只能删除没有子项的栏目 if (GetSortedListByParentId(id).Count == 0) { var nav = GetDetail(id); context.FrontendNavigations.Attach(nav); context.FrontendNavigations.Remove(nav); context.LogChangesDuringSave = true; return context.SaveChanges(); } return 0; } }
public int Delete(string id) { using (var context = new WSI.DataAccess.WSICmsContext()) { var item = GetDetail(id); if (item != null) { context.Attachments.Attach(item); var info = context.Informations.Find(item.InformationId); //先将该附件从信息中移除 info.Attachments.Remove(item); context.Attachments.Remove(item); } context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public void Add(string name, string password, IList<string> roleidlist) { using (var context = new WSI.DataAccess.WSICmsContext()) { UserInfo user = new UserInfo(); //user.UserId = Guid.NewGuid(); user.UserName = name; user.UserPassword = password.EncryptMD5(); user.CreateTime = DateTime.Now; user.LastVisitTime = DateTime.Now; user.State = (int)EnumHelper.State.Disable; //添加角色 setRoleInfo(context, user, roleidlist); context.UserInfoes.Add(user); context.LogChangesDuringSave = true; context.SaveChanges(); } }
public void AddRecruitment(string position, string department, string workplace, string duty, string requirement, DateTime publishTime) { using (var context = new WSI.DataAccess.WSICmsContext()) { var recruit = new Recruitment() { Position = position, Department = department, WorkPlace = workplace, Duty = duty, Requirement = requirement, PublishTime = publishTime }; context.Recruitments.Add(recruit); context.LogChangesDuringSave = true; context.SaveChanges(); } }
public void AddCookBook( string name, string summary, string source, string referenceUrl, string materail, string benifits, string practice, string tips, string navid, bool isRecommend) { using (var context = new WSI.DataAccess.WSICmsContext()) { context.CookBooks.Add(new CookBook() { CookBookName = name, Summary = summary, Source = source, ReferenceUrl = referenceUrl, Material = materail, Benifits = benifits, Practice = practice, Tips = tips, NavigationId = Guid.Parse(navid), IsRecommend = isRecommend, ImageUrl = "", LikeCount = 0, State = (int)EnumHelper.State.Disable, CreateTime = DateTime.Now }); context.LogChangesDuringSave = true; context.SaveChanges(); } }
public void UpdateImage(string cbid, string path) { using (var context = new WSI.DataAccess.WSICmsContext()) { var item = GetDetail(cbid); context.CookBooks.Attach(item); item.ImageUrl = path; context.LogChangesDuringSave = true; context.SaveChanges(); } }
public void UpdateCookBook( string cbid, string name, string summary, string source, string referenceUrl, string materail, string benifits, string practice, string tips, string navid, bool isRecommend) { using (var context = new WSI.DataAccess.WSICmsContext()) { var item = GetDetail(cbid); context.CookBooks.Attach(item); item.CookBookName = name; item.Summary = summary; item.Source = source; item.ReferenceUrl = referenceUrl; item.Material = materail; item.Benifits = benifits; item.Practice = practice; item.Tips = tips; item.NavigationId = Guid.Parse(navid); item.IsRecommend = isRecommend; context.LogChangesDuringSave = true; context.SaveChanges(); } }
public int UpdateNavigation(string nid, string parentId, string navName, string url, int type, string description) { using (var context = new WSI.DataAccess.WSICmsContext()) { FrontendNavigation nav = GetDetail(nid); context.FrontendNavigations.Attach(nav); if (nav != null) { nav.NavName = navName; nav.Url = url; nav.Type = type; nav.Description = description; //添加父导航 Guid pid; if (Guid.TryParse(parentId, out pid)) { nav.Parent = context.FrontendNavigations.Find(pid); } } context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public int UpdateTagInformation(string tagId, string infoId) { using (var context = new WSI.DataAccess.WSICmsContext()) { //从关联表中取出tagId对应的所有信息 Guid tag; Guid info; var exists = new List<Guid>(); if (Guid.TryParse(tagId, out tag)) { exists = (from r in context.TagInformations where r.TagId == tag select r.Information.InfoId).ToList(); } if (Guid.TryParse(infoId, out info)) { //添加 if (!exists.Contains(info)) { context.TagInformations.Add(new TagInformation() { TagId = tag, InfoId = info, SortIndex = exists.Count() }); } } context.LogChangesDuringSave = true; return context.SaveChanges(); } }
//更新信息 public int UpdateTag(string tagId, string parentId, string tagName, string code, string description) { using (var context = new WSI.DataAccess.WSICmsContext()) { Tag tag = GetDetail(tagId); context.Tags.Attach(tag); if (tag != null) { tag.TagName = tagName; tag.TagCode = code; tag.Description = description; //父标签 Guid pid; if (Guid.TryParse(parentId, out pid)) { tag.Parent = context.Tags.Find(pid); } } context.LogChangesDuringSave = true; return context.SaveChanges(); } }
public void ResortTagInformation(string tagId, IList<string> sortedlist) { using (var context = new WSI.DataAccess.WSICmsContext()) { Guid tag; if (Guid.TryParse(tagId, out tag)) { foreach (var infoid in sortedlist) { Guid info; if (Guid.TryParse(infoid, out info)) { var item = context.TagInformations .Where(r => r.TagId == tag) .Where(r => r.InfoId == info) .SingleOrDefault(); item.SortIndex = sortedlist.IndexOf(infoid); } } context.SaveChanges(); } } }
public void ReSort(IList<string> sortedlist) { using (var context = new WSI.DataAccess.WSICmsContext()) { foreach (var id in sortedlist) { var tag = GetDetail(id); if (tag != null) { context.Tags.Attach(tag); tag.SortIndex = sortedlist.IndexOf(id); } } context.SaveChanges(); } }
public int Favor(string id) { using (var context = new WSI.DataAccess.WSICmsContext()) { var item = GetDetail(id); context.CookBooks.Attach(item); item.LikeCount = item.LikeCount + 1; context.SaveChanges(); return item.LikeCount; } }
public void ReSort(IList<string> sortedlist) { using (var context = new WSI.DataAccess.WSICmsContext()) { foreach (var id in sortedlist) { var nav = GetDetail(id); if (nav != null) { context.FrontendNavigations.Attach(nav); nav.SortIndex = sortedlist.IndexOf(id); } } context.SaveChanges(); } }