Example #1
0
        public virtual ActionResult AddMedia(AddMediaVM.AddMediaPurpose purpose, AddMediaVM.AddMediaType type, long? memberId)
        {
            ActionResult returnValue = null;
            AddMediaVM viewModel = new AddMediaVM
            {
                Type = type,
                Purpose = purpose
            };
            if (purpose == AddMediaVM.AddMediaPurpose.TinyMce || purpose == AddMediaVM.AddMediaPurpose.ProfileImageAjax)
            {
                returnValue = View(MVC.Shared.Views.AddMediaStandalone, viewModel);
            }
            else if (purpose == AddMediaVM.AddMediaPurpose.ProfileImage)
            {
                returnValue = View("AddMedia", viewModel);
            }
            else
            {
                if (this.Request.IsAjaxRequest())
                {
                    var viewModelError = new AjaxReturnMsgVM
                    {
                        StatusCode = AjaxReturnMsgVM.Status.failure,
                        StatusMessage = "Unsupported purpose"
                    };

                    returnValue = Json(viewModelError);
                }
                else
                {
                    var viewModelError = new MessageVM
                    {
                        Image = ImageLibrary.Alert,
                        CssClassContainer = "failure",
                        Message = "Unsupported purpose ",
                        Title = ErrorStrings.TITLE_ERROR,
                        LinkText = "Continue",
                        LinkHref = Url.Action(MVC.Home.Index()),
                    };

                    returnValue = View("Message", viewModelError);
                }
            }

            return returnValue;
        }
Example #2
0
        public virtual ActionResult AddMedia(AddMediaVM model)
        {
            ActionResult returnValue = null;
            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;
            ProviderMember aMember = null;

            // try to get the member from the model, otherwise just use current member
            // TODO check this logic
            if (model.MemberId != null)
            {
                aMember = new ProviderMember(model.MemberId.Value);
            }
            else
            {
                aMember = currentMember;
            }

            HttpPostedFileBase filePhoto = Request.Files[model.FilePhotoKey] as HttpPostedFileBase;
            bool isValidPhoto = ProviderPhoto.Validate(filePhoto);
            ProviderPhoto originalPhoto = null;

            if (isValidPhoto)
            {
                originalPhoto = PhotoBL.CreatePhoto(aMember, filePhoto);
            }

            if (model.Purpose == AddMediaVM.AddMediaPurpose.TinyMce)
            {
                if (isValidPhoto)
                {
                    returnValue = View("AddMediaDone", new AddMediaDoneVM { FileURL = originalPhoto.ImageUrl.AbsoluteUri });
                }
                else
                {
                    ModelState.AddModelError("", ErrorStrings.INVALID_IMAGE);
                    returnValue = View(MVC.Shared.Views.AddMediaStandalone, model);
                }
            }
            else if (model.Purpose == AddMediaVM.AddMediaPurpose.ProfileImage || model.Purpose == AddMediaVM.AddMediaPurpose.ProfileImageAjax)
            {
                if(isValidPhoto)
                {
                    aMember.ProfilePhotoId = originalPhoto.Id;
                    aMember.Save();
                }

                if (model.Purpose == AddMediaVM.AddMediaPurpose.ProfileImageAjax)
                {
                    var viewModel = new AjaxReturnMsgVM();
                    if(isValidPhoto)
                    {
                        viewModel.StatusCode = AjaxReturnMsgVM.Status.success;
                        viewModel.StatusMessage = originalPhoto.Thumbnail(ProviderPhotoRecord.ImageTypeEnum.ProfileThumbnail)
                                                               .ImageUrl
                                                               .AbsoluteUri;
                    }
                    else
                    {
                        viewModel.StatusCode = AjaxReturnMsgVM.Status.failure;
                        viewModel.StatusMessage = ErrorStrings.INVALID_IMAGE;
                    }
                    returnValue = Json(viewModel);
                }
                else if (model.Purpose == AddMediaVM.AddMediaPurpose.ProfileImage)
                {
                    if (isValidPhoto)
                    {
                        var viewModel = new MessageVM
                        {
                            Image = ImageLibrary.Success,
                            CssClassContainer = "success",
                            Message = "Profile Image updated",
                            Title = "Profile Image updated",
                            LinkText = "Continue",
                            LinkHref = Url.Action(MVC.Member.Account(aMember.Id.Value, null)),
                        };
                        returnValue = View("Message", viewModel);
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorStrings.INVALID_IMAGE);
                        returnValue = View(model);
                    }
                }
            }
            else
            {
                if(this.Request.IsAjaxRequest())
                {
                    var viewModel = new AjaxReturnMsgVM
                    {
                        StatusCode = AjaxReturnMsgVM.Status.failure,
                        StatusMessage = "Unsupported purpose"
                    };

                    returnValue = Json(viewModel);
                }
                else
                {
                    var viewModel = new MessageVM
                    {
                        Image = ImageLibrary.Alert,
                        CssClassContainer = "failure",
                        Message = "Unsupported purpose ",
                        Title = ErrorStrings.TITLE_ERROR,
                        LinkText = "Continue",
                        LinkHref = Url.Action(MVC.Home.Index()),
                    };

                    returnValue = View("Message", viewModel);
                }
            }

            return returnValue;
        }