/// <summary> /// Save client menu manage model /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveClientMenuManageModel(ClientMenuManageModel model) { ClientMenu relativeMenu; ResponseModel response; var clientMenu = GetById(model.Id); #region Edit ClientMenu if (clientMenu != null) { clientMenu.Name = model.Name; clientMenu.IncludeInSiteNavigation = model.IncludeInSiteNavigation; clientMenu.StartPublishingDate = model.StartPublishingDate; clientMenu.EndPublishingDate = model.EndPublishingDate; //Parse url clientMenu.Url = string.IsNullOrWhiteSpace(model.Url) ? model.Name.ToUrlString() : model.Url.ToUrlString(); //Get page record order relativeMenu = GetById(model.RelativeMenuId); if (relativeMenu != null) { if (model.Position == (int)ClientMenuEnums.PositionEnums.Before) { clientMenu.RecordOrder = relativeMenu.RecordOrder; var query = string.Format( "Update ClientMenus set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder >= {1}", relativeMenu.ParentId.HasValue ? string.Format(" ParentId = {0}", relativeMenu.ParentId) : "ParentId Is NULL", relativeMenu.RecordOrder); _pageRepository.ExcuteSql(query); } else { clientMenu.RecordOrder = relativeMenu.RecordOrder + 1; var query = string.Format( "Update ClientMenus set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder > {1}", relativeMenu.ParentId.HasValue ? string.Format(" ParentId = {0}", relativeMenu.ParentId) : "ParentId Is NULL", relativeMenu.RecordOrder); _pageRepository.ExcuteSql(query); } } clientMenu.ParentId = model.ParentId; response = HierarchyUpdate(clientMenu); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::ClientMenus:::Messages:::UpdateSuccessfully:::Update client menu successfully.") : _localizedResourceServices.T("AdminModule:::ClientMenus:::Messages:::UpdateFailure:::Update client menu failed. Please try again later."))); } #endregion clientMenu = new ClientMenu { Name = model.Name, ParentId = model.ParentId, IncludeInSiteNavigation = model.IncludeInSiteNavigation, StartPublishingDate = model.StartPublishingDate, EndPublishingDate = model.EndPublishingDate, Url = string.IsNullOrWhiteSpace(model.Url) ? model.Name.ToUrlString() : model.Url.ToUrlString() }; //Get menu record order relativeMenu = GetById(model.RelativeMenuId); if (relativeMenu != null) { if (model.Position == (int)ClientMenuEnums.PositionEnums.Before) { clientMenu.RecordOrder = relativeMenu.RecordOrder - 1; } else { clientMenu.RecordOrder = relativeMenu.RecordOrder + 1; } } response = HierarchyInsert(clientMenu); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::ClientMenus:::Messages:::CreateSuccessfully:::Create client menu successfully.") : _localizedResourceServices.T("AdminModule:::ClientMenus:::Messages:::CreateFailure:::Create client menu failed. Please try again later."))); }
/// <summary> /// Save page manage model /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SavePageManageModel(PageManageModel model) { Page relativePage; ResponseModel response; var page = GetById(model.Id); #region Edit Page if (page != null) { var pageLog = new PageLogManageModel(page); page.Title = model.Title; page.PageTemplateId = model.PageTemplateId; page.FileTemplateId = model.FileTemplateId; page.Status = model.Status; //Set content & caption base on status if (model.Status == (int)PageEnums.PageStatusEnums.Draft) { page.ContentWorking = model.Content; page.CaptionWorking = model.Caption; } else { page.Content = model.Content; page.Caption = model.Caption; } var currentTags = page.PageTags.Select(t => t.TagId).ToList(); foreach (var id in currentTags.Where(id => model.Tags == null || !model.Tags.Contains(id))) { _pageTagRepository.Delete(page.Id, id); } if (model.Tags != null && model.Tags.Any()) { foreach (var tagId in model.Tags) { if (currentTags.All(n => n != tagId)) { var pageTag = new PageTag { PageId = page.Id, TagId = tagId }; _pageTagRepository.Insert(pageTag); } } } page.StartPublishingDate = model.StartPublishingDate; page.EndPublishingDate = model.EndPublishingDate; //Parse friendly url page.FriendlyUrl = string.IsNullOrWhiteSpace(model.FriendlyUrl) ? model.Title.ToUrlString() : model.FriendlyUrl.ToUrlString(); //Get page record order relativePage = GetById(model.RelativePageId); if (relativePage != null) { /* * If position is not changed, donot need to update order of relative pages * If position is changed, check if position is before or after and update the record other of all relative pages */ var relativePages = Fetch(p => p.Id != page.Id && relativePage.ParentId.HasValue ? p.ParentId == relativePage.ParentId : p.ParentId == null) .OrderBy(p => p.RecordOrder); if (model.Position == (int)PageEnums.PositionEnums.Before) { if (page.RecordOrder > relativePage.RecordOrder || relativePages.Any(p => p.RecordOrder > page.RecordOrder && p.RecordOrder < relativePage.RecordOrder)) { page.RecordOrder = relativePage.RecordOrder; var query = string.Format( "Update Pages set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder >= {1}", relativePage.ParentId.HasValue ? string.Format(" ParentId = {0}", relativePage.ParentId) : "ParentId Is NULL", relativePage.RecordOrder); _pageRepository.ExcuteSql(query); } } else { if (page.RecordOrder < relativePage.RecordOrder || relativePages.Any(p => p.RecordOrder < page.RecordOrder && p.RecordOrder > relativePage.RecordOrder)) { page.RecordOrder = relativePage.RecordOrder + 1; var query = string.Format( "Update Pages set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder > {1}", relativePage.ParentId.HasValue ? string.Format(" ParentId = {0}", relativePage.ParentId) : "ParentId Is NULL", relativePage.RecordOrder); _pageRepository.ExcuteSql(query); } } } page.ParentId = model.ParentId; response = HierarchyUpdate(page); if (response.Success) { _clientMenuServices.SavePageToClientMenu(page.Id); _pageLogServices.SavePageLog(pageLog); } return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::Pages:::Messages:::UpdateSuccessfully:::Update page successfully.") : _localizedResourceServices.T("AdminModule:::Pages:::Messages:::UpdateFailure:::Update page failed. Please try again later."))); } #endregion page = new Page { Title = model.Title, Status = model.Status, Content = model.Content, Caption = model.Caption, ParentId = model.ParentId, RecordOrder = 0, PageTemplateId = model.PageTemplateId, FileTemplateId = model.FileTemplateId, FriendlyUrl = string.IsNullOrWhiteSpace(model.FriendlyUrl) ? model.Title.ToUrlString() : model.FriendlyUrl.ToUrlString() }; //Set content & caption base on status if (model.Status == (int)PageEnums.PageStatusEnums.Draft) { page.ContentWorking = model.Content; page.CaptionWorking = model.Caption; } //Get page record order relativePage = GetById(model.RelativePageId); if (relativePage != null) { if (model.Position == (int)PageEnums.PositionEnums.Before) { page.RecordOrder = relativePage.RecordOrder; var query = string.Format( "Update Pages set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder >= {1}", relativePage.ParentId.HasValue ? string.Format(" ParentId = {0}", relativePage.ParentId) : "ParentId Is NULL", relativePage.RecordOrder); _pageRepository.ExcuteSql(query); } else { page.RecordOrder = relativePage.RecordOrder + 1; var query = string.Format( "Update Pages set RecordOrder = RecordOrder + 1 Where {0} And RecordOrder > {1}", relativePage.ParentId.HasValue ? string.Format(" ParentId = {0}", relativePage.ParentId) : "ParentId Is NULL", relativePage.RecordOrder); _pageRepository.ExcuteSql(query); } } response = HierarchyInsert(page); if (response.Success) { _clientMenuServices.SavePageToClientMenu(response.Data.ToInt()); } return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::Pages:::Messages:::CreateSuccessfully:::Create page successfully.") : _localizedResourceServices.T("AdminModule:::Pages:::Messages:::CreateFailure:::Create page failed. Please try again later."))); }