コード例 #1
0
ファイル: ChildController.cs プロジェクト: Thirlan/insideword
        public virtual JsonResult EditAlternateCategory(long memberId, AlternateCategoryListVM model)
        {
            PartialPostVM returnValue = null;
            ProviderMember aMember = new ProviderMember(model.MemberId);
            if (ModelState.IsValid)
            {
                try
                {
                    ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;
                    if (!currentMember.CanEdit(aMember))
                    {
                        // TODO: Replace this by throwing a real HTML 401 status code
                        Redirect(Url.Action(MVC.Error.Index(401)));
                    }
                    else if (!MemberBL.SaveAlternateCategories(model, aMember))
                    {
                        ModelState.AddModelError("", "Failed to save the alternate category changes. An administrator will contact you through e-mail regarding this issue.");
                    }
                    else
                    {
                        returnValue = new PartialPostVM
                        {
                            Action = PartialPostVM.ActionType.redirect,
                            Message = String.Empty,
                            Content = Request.UrlReferrer.AbsoluteUri
                        };
                    }
                }
                catch (Exception caughtException)
                {
                    InsideWordWebLog.Instance.Log.Error(caughtException);
                    ModelState.AddModelError("", "Failed to save the alternate category changes. An administrator will contact you through e-mail regarding this issue.");
                }
            }

            if (returnValue == null)
            {
                model.Refresh(aMember, ProviderCategory.Root.Children());
                returnValue = new PartialPostVM
                {
                    Action = PartialPostVM.ActionType.refresh,
                    Message = String.Empty,
                    Content = ControllerExtension.RenderPartialViewToString(this, MVC.Child.Views.EditAlternateCategory, (object)model)
                };
            }

            return Json(returnValue);
        }
コード例 #2
0
ファイル: MemberBL.cs プロジェクト: Thirlan/insideword
        public static bool SaveAlternateCategories(AlternateCategoryListVM model, ProviderMember aMember)
        {
            List<ProviderAlternateCategoryId> alternateList = aMember.AlternateCategoryList;
            ProviderCategory defaultCategory = new ProviderCategory(InsideWordSettingsDictionary.Instance.DefaultCategoryId.Value);
            foreach(AlternateCategoryMapVM aMap in model.AlternateCategoryMapList)
            {
                ProviderAlternateCategoryId altCategory = null;
                if (alternateList.Exists(altId => altId.AlternateId == aMap.AlternateId))
                {
                    altCategory = alternateList.Find(altId => altId.AlternateId == aMap.AlternateId);
                }
                else
                {
                    altCategory = new ProviderAlternateCategoryId();
                    altCategory.AlternateId = aMap.AlternateId;
                    altCategory.MemberId = aMember.Id.Value;
                }

                if (aMap.MapId.HasValue)
                {
                    if (aMap.MapId == -1)
                    {
                        aMap.MapId = defaultCategory.Id;
                    }

                    if (altCategory.CategoryId != aMap.MapId)
                    {
                        altCategory.CategoryId = aMap.MapId;
                        if (!altCategory.IsNew)
                        {
                            // The category map changed. Re-categorize all articles related to this alternate category.
                            AsyncRefreshArticleManager.Instance.AddBy(AsyncRefreshArticleManager.LoadEnum.AltCategory, altCategory.Id.Value);
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(aMap.AlternateTitle))
                {
                    altCategory.DisplayName = aMap.AlternateTitle;
                }
                altCategory.OverrideFlag = model.OverrideFlag;
                altCategory.Save();
            }

            return true;
        }