コード例 #1
0
        public async Task <IActionResult> CreateHashIDPostedJson([FromBody] Models.UrlString longUrl)
        {
            if (ModelState.IsValid && URLValidator.IsUrlValid(longUrl.url))
            {
                Models.ShortLink hashIDItem = await HashIDDBRepository.CreateHashIDItemIfNotExistsAsync(longUrl.url);

                Models.PublicShortLink response = new Models.PublicShortLink
                {
                    Url         = hashIDItem.Url,
                    HashID      = hashIDItem.HashID,
                    CreatedTime = hashIDItem.CreatedTime
                };
                // Determine if hashID exists in cache.
                // Move hashID to front if hashID exists in cache.
                if (ReadUrlCache.Get(response.HashID) == null)
                {
                    // Add new hashID to cache.
                    ReadUrlCache.Add(response.HashID, response.Url);
                }
                return(Ok(response));
            }
            else
            {
                Models.ErrorResponse invalidURLResponse = new Models.ErrorResponse
                {
                    Details = "Enter a valid URL."
                };
                return(BadRequest(invalidURLResponse));
            }
        }
コード例 #2
0
        //// GET: api/User/5
        //public ErrorResponse Get(int id)
        //{
        //    // future; add proper authentication and allow user to request cart info

        //    // only return
        //    ErrorResponse er = new Models.ErrorResponse();
        //    er.code = 400;
        //    er.developerMessage = "Not presently implemented.Do not retry.";
        //    er.message = er.developerMessage;
        //    er.moreInfo = "";
        //    er.property = "";
        //    er.status = 403;
        //    return er;
        //}


        // POST: api/User
        public IHttpActionResult Post([FromBody] UserRequest req)
        {
            if (req.pid < 0)
            {
                ErrorResponse er = new Models.ErrorResponse();
                er.code             = 400;
                er.developerMessage = "Missing parent ID (pid) parameter. Permanent failure. Do not retry.";
                er.property         = "pid";
                er.status           = 400;
                return(Content(HttpStatusCode.BadRequest, er));
            }

            User u = new User(req.pid, ConfigurationManager.AppSettings["AccountStoreKey"]);

            /* required fields */
            u.ParentId        = req.pid;
            u.PersonFirstname = req.Firstname;
            u.PersonLastname  = req.Lastname;
            u.EmailAddress    = req.Email;
            u.Username        = req.Username;
            u.SetPassword(req.Password);


            if (!String.IsNullOrEmpty(req.CompanyName))
            {
                u.AccountName = req.CompanyName;
            }
            u.BillingAddress1    = req.BillingAddress1;
            u.BillingAddress2    = req.BillingAddress2;
            u.BillingCity        = req.BillingCity;
            u.BillingStateCode   = req.BillingStateCode;
            u.BillingPostalCode  = req.BillingPostalCode;
            u.BillingCountryCode = req.BillingCountryCode;

            u.ShippingAddress1    = req.ShippingAddress1;
            u.ShippingAddress2    = req.ShippingAddress2;
            u.ShippingCity        = req.ShippingCity;
            u.ShippingStateCode   = req.ShippingStateCode;
            u.ShippingPostalCode  = req.ShippingPostalCode;
            u.ShippingCountryCode = req.ShippingCountryCode;

            u.PhoneNumber = req.PhoneNumber;
            u.Url         = req.Url;

            if (u.Create() == true)
            {
                return(Content(HttpStatusCode.OK, u.UserResponse));
            }
            else
            {
                // return the user model's error response
                return(Content(HttpStatusCode.BadRequest, u.ErrorResponse));
            }
        }
コード例 #3
0
        // GET: api/User
        public IHttpActionResult Get()
        {
            ErrorResponse er = new Models.ErrorResponse();

            er.code             = 400;
            er.developerMessage = "Only POST method allowed. Permanent failure. Do not retry.";
            er.message          = er.developerMessage;
            er.moreInfo         = "n.a.";
            er.property         = "n.a.";
            er.status           = 400;
            return(Content(HttpStatusCode.BadRequest, er));
        }
コード例 #4
0
        public String AddSongToPlayList(String playlistName, String songName, String artist)
        {
            if (mProfile == null || mSpotify == null)
            {
                return("you need to connect to spotify before you can use this feature");
            }

            if (playlists == null)
            {
                playlists = mSpotify.GetUserPlaylists(mProfile.Id).Items;
            }

            Models.SimplePlaylist playlist = playlists.Find(x => x.Name == playlistName);

            if (playlist == null)
            {
                return($"could not find playlist {playlistName}");
            }

            Models.SearchItem search = mSpotify.SearchItems(songName, Enums.SearchType.Track);

            if (search.Tracks == null || search.Tracks.Items.Count == 0)
            {
                return($"could not find song {songName}");
            }

            Models.FullTrack songData = search.Tracks.Items.Find(x => String.Equals(x.Artists[0].Name, artist, StringComparison.OrdinalIgnoreCase));

            if (songData == null)
            {
                return($"could not find song {songName} by {artist}");
            }

            Models.ErrorResponse error = mSpotify.AddPlaylistTrack(mProfile.Id, playlist.Id, songData.Uri);

            if (error.Error != null)
            {
                return(error.Error.Message);
            }

            return($"{songName} by {artist} was sucessfully added to {playlistName}");
        }
コード例 #5
0
        public async Task <IActionResult> Get(string hashID)
        {
            string redirectUrl = ReadUrlCache.Get(hashID);

            if (redirectUrl != null)
            {
                return(Redirect(redirectUrl));
            }
            Models.ShortLink hashIDItem = await HashIDDBRepository.GetHashIDItemAsync(hashID);

            if (hashIDItem == null)
            {
                Models.ErrorResponse notFoundResponse = new Models.ErrorResponse
                {
                    Details = "Not found."
                };
                return(NotFound(notFoundResponse));
            }
            else
            {
                return(Redirect(hashIDItem.Url));
            }
        }
コード例 #6
0
 // Executado quando a requisição de consulta dos autores falha.
 void Handle_RequestFailed(object sender, Models.ErrorResponse e)
 {
     // Mostra alerta.
     DisplayAlert("Erro", e.Message, "ok");
 }