Exemple #1
0
 bool CanEdit(ArtistPage ArtistPage)
 {
     if (ArtistPage == null)
     {
         return(false);
     }
     return(_workContext.CurrentCustomer.Id == ArtistPage.PageOwnerId || //page owner
            _workContext.CurrentCustomer.IsAdmin() || //administrator
            _artistPageManagerService.IsPageManager(ArtistPage.Id, _workContext.CurrentCustomer.Id)); //page manager
 }
        public IHttpActionResult SavePageManager(int artistPageId, int customerId)
        {
            //let's perform a few checks before saving the page manager
            //1. does the artist page exist and is the current user eligible to add manager?
            var artistPage = _artistPageService.Get(artistPageId);

            if (artistPage != null && CanDelete(artistPage))
            {
                //2. does the customer really exist?
                var customer = _userService.Get(customerId);
                if (customer != null)
                {
                    //3. is the customer already a page manager
                    if (_artistPageManagerService.IsPageManager(artistPageId, customerId))
                    {
                        VerboseReporter.ReportError("The user is already the page manager for this page", "save_page_manager");
                        return(RespondFailure());
                    }
                    //enough checks...save the new manager now
                    _artistPageManagerService.AddPageManager(new ArtistPageManager()
                    {
                        ArtistPageId = artistPageId,
                        CustomerId   = customerId,
                    });

                    return(RespondSuccess());
                }
                else
                {
                    VerboseReporter.ReportError("The user doesn't exists", "save_page_manager");
                    return(RespondFailure());
                }
            }
            else
            {
                VerboseReporter.ReportError("Unauthorized", "save_page_manager");
                return(RespondFailure());
            }
        }