Ejemplo n.º 1
0
        public ActionResult Editor(int ArtistPageId = 0)
        {
            ArtistPageModel model = null;

            if (ArtistPageId != 0)
            {
                var artist = _artistPageService.GetById(ArtistPageId);
                //can the current user edit this page?
                if (CanEdit(artist))
                {
                    model = new ArtistPageModel()
                    {
                        Description      = artist.Biography,
                        DateOfBirth      = artist.DateOfBirth,
                        City             = artist.HomeTown,
                        Gender           = artist.Gender,
                        Name             = artist.Name,
                        ShortDescription = artist.ShortDescription,
                        RemoteEntityId   = artist.RemoteEntityId,
                        RemoteSourceName = artist.RemoteSourceName,
                        HomeTown         = artist.HomeTown
                    };
                }
                else
                {
                    return(InvokeHttp404());
                }
            }
            else
            {
                model = new ArtistPageModel();
            }

            return(View(ControllerUtil.MobSocialViewsFolder + "/ArtistPage/Editor.cshtml", model));
        }
        public IHttpActionResult Editor(int artistPageId = 0)
        {
            ArtistPageModel model = null;

            if (artistPageId != 0)
            {
                var artist = _artistPageService.Get(artistPageId);
                //can the current user edit this page?
                if (CanEdit(artist))
                {
                    model = new ArtistPageModel()
                    {
                        Description      = artist.Biography,
                        DateOfBirth      = artist.DateOfBirth,
                        Gender           = artist.Gender,
                        Name             = artist.Name,
                        ShortDescription = artist.ShortDescription,
                        RemoteEntityId   = artist.RemoteEntityId,
                        RemoteSourceName = artist.RemoteSourceName,
                        HomeTown         = artist.HomeTown
                    };
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                model = new ArtistPageModel();
            }

            return(Response(model));
        }
        public IHttpActionResult Get(int id)
        {
            var artist = _artistPageService.Get(id);

            if (artist == null)
            {
                return(NotFound());
            }

            var model = new ArtistPageModel()
            {
                Description      = artist.Biography,
                DateOfBirth      = artist.DateOfBirth,
                Gender           = artist.Gender,
                Name             = artist.Name,
                ShortDescription = artist.ShortDescription,
                HomeTown         = artist.HomeTown,
                RemoteEntityId   = artist.RemoteEntityId,
                RemoteSourceName = artist.RemoteSourceName,
                Id = artist.Id
            };

            //images for artist
            foreach (var picture in artist.GetPictures())
            {
                model.Pictures.Add(new PictureResponseModel {
                    Id         = picture.Id,
                    PictureUrl = _pictureService.GetPictureUrl(picture),
                });
            }

            model.CanEdit   = CanEdit(artist);
            model.CanDelete = CanDelete(artist);

            return(Response(model));
        }
        public IHttpActionResult SaveArtist(ArtistPageModel model)
        {
            if (!ModelState.IsValid)
            {
                VerboseReporter.ReportError("Invalid data submitted. Please check all fields and try again.", "save_artist");
                return(RespondFailure());
            }

            if (!ApplicationContext.Current.CurrentUser.IsRegistered())
            {
                VerboseReporter.ReportError("Unauthorized access", "save_artist");
                return(RespondFailure());
            }

            //check to see if artist name already exists
            string artistJson;

            if (IsArtistPageNameAvailable(model.Name, out artistJson))
            {
                var artistPage = new ArtistPage()
                {
                    PageOwnerId      = ApplicationContext.Current.CurrentUser.Id,
                    Biography        = model.Description,
                    Name             = model.Name,
                    DateOfBirth      = model.DateOfBirth,
                    Gender           = model.Gender,
                    HomeTown         = model.HomeTown,
                    RemoteEntityId   = model.RemoteEntityId,
                    RemoteSourceName = model.RemoteSourceName,
                    ShortDescription = model.ShortDescription
                };

                _artistPageService.Insert(artistPage);

                if (artistJson != "")
                {
                    //we can now download the image from the server and store it on our own server
                    //use the json we retrieved earlier
                    var jObject = (JObject)JsonConvert.DeserializeObject(artistJson);

                    if (!string.IsNullOrEmpty(jObject["ImageUrl"].ToString()))
                    {
                        var imageUrl      = jObject["ImageUrl"].ToString();
                        var imageBytes    = HttpHelper.ExecuteGet(imageUrl);
                        var fileExtension = Path.GetExtension(imageUrl);
                        if (!string.IsNullOrEmpty(fileExtension))
                        {
                            fileExtension = fileExtension.ToLowerInvariant();
                        }

                        var contentType = PictureUtility.GetContentType(fileExtension);
                        var picture     = new Media()
                        {
                            Binary   = imageBytes,
                            Name     = model.Name,
                            MimeType = contentType
                        };
                        _pictureService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);
                        //relate both page and picture
                        _pictureService.AttachMediaToEntity(artistPage, picture);
                    }
                }

                return(Response(new {
                    Success = true,
                    RedirectTo = Url.Route("ArtistPageUrl", new RouteValueDictionary()
                    {
                        { "SeName", artistPage.GetPermalink() }
                    })
                }));
            }
            else
            {
                return(Response(new {
                    Success = false,
                    Message = "DuplicateName"
                }));
            }
        }