예제 #1
0
        public static bool SavePersonalInfo(PersonalInfoVM model, ProviderMember aMember)
        {
            // save username and bio.  everything else is saved asynchronously through other methods
            aMember.Bio = model.Bio;
            aMember.Save();

            if (string.IsNullOrWhiteSpace(model.UserName))
            {
                // If someone blanked out their username then delete it.
                // Otherwise it was just blank so do nothing.
                if (aMember.UserNames.Count > 0)
                {
                    aMember.UserNames[0].Delete();
                }
            }
            else
            {
                // If the user name was not blank then create it
                ProviderUserName userName;
                if (aMember.UserNames.Count > 0)
                {
                    userName = aMember.UserNames[0];
                }
                else
                {
                    userName = new ProviderUserName();
                    userName.MemberId = aMember.Id.Value;
                    userName.CreateDate = DateTime.UtcNow;
                }
                userName.EditDate = DateTime.UtcNow;
                userName.UserName = model.UserName;
                userName.Save();
            }

            return true;
        }
예제 #2
0
        public virtual JsonResult EditPersonalInfo(long memberId, PersonalInfoVM model)
        {
            PartialPostVM returnValue = null;
            if (ModelState.IsValid)
            {
                try
                {
                    ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;
                    ProviderMember aMember = new ProviderMember(model.MemberId);
                    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.SavePersonalInfo(model, aMember))
                    {
                        ModelState.AddModelError("", "Failed to update personal info. 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 update personal info. An administrator will contact you through e-mail regarding this issue.");
                }
            }

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

            return Json(returnValue);
        }