Ejemplo n.º 1
0
        /// <summary>
        /// Edit the entity by passing in the form collection so it maps the
        /// html fields to the entity properites.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="collection"></param>
        /// <param name="fetcher"></param>
        /// <returns></returns>
        public override ActionResult Edit(Profile updated)
        {
            DashboardLayout(true);
            EntityActionResult result = null;

            try
            {
                result = _helper.Edit(updated, (original) =>
                {
                    // Copy back the original values.
                    updated.UserId   = original.UserId;
                    updated.UserName = original.UserName;
                    ProfileHelper.ChangeEmail(updated, original);

                    if (!updated.Errors.HasAny)
                    {
                        ProfileHelper.ApplyProfileImage(updated);
                    }
                });
            }
            catch
            {
                result = new EntityActionResult(false, "Error while updating profile", item: updated, isAuthorized: true, isAvailable: true);
            }

            return(BuildRedirectResult(result, successAction: _viewSettings.ActionForCreationSuccess, routeValues: new { id = updated.Id },
                                       viewLocationForErrors: _viewSettings.PageLocationForEdit, viewActionForErrors: "Edit"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the photo thumbnail as a json response, result object contains "Success:bool, Message:string, Item:string" fields.
        /// </summary>
        /// <param name="id">The id of the profile.</param>
        /// <returns></returns>
        public ActionResult ApplyProfilePhoto(int id)
        {
            var result = _helper.Edit(id);

            if (!result.Success)
            {
                return(Json(new { Success = false, Message = result.Message }, JsonRequestBehavior.AllowGet));
            }

            var profile = result.ItemAs <Profile>();

            ProfileHelper.ApplyProfileImage(profile);
            profile.Save();
            var success = !profile.Errors.HasAny;
            var message = success ? string.Empty : profile.Errors.Message("<br/>");

            return(Json(new { Success = success, Message = message }, JsonRequestBehavior.AllowGet));
        }