Exemplo n.º 1
0
        public ActionResult GetPerson(int id)
        {
            /*Calling API https://developers.themoviedb.org/3/people */
            string         apiKey     = "3356865d41894a2fa9bfa84b2b5f59bb";
            HttpWebRequest apiRequest = WebRequest.Create("https://api.themoviedb.org/3/person/" + id + "?api_key=" + apiKey + "&language=en-US") as HttpWebRequest;

            string apiResponse = "";

            using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                apiResponse = reader.ReadToEnd();
            }
            /*End*/

            /*http://json2csharp.com*/
            ResponsePerson rootObject = JsonConvert.DeserializeObject <ResponsePerson>(apiResponse);
            TheMovieDb     theMovieDb = new TheMovieDb();

            theMovieDb.name           = rootObject.name;
            theMovieDb.biography      = rootObject.biography;
            theMovieDb.birthday       = rootObject.birthday;
            theMovieDb.place_of_birth = rootObject.place_of_birth;
            theMovieDb.profile_path   = rootObject.profile_path == null?Url.Content("~/Content/Image/no-image.png") : "https://image.tmdb.org/t/p/w500/" + rootObject.profile_path;

            theMovieDb.also_known_as = string.Join(", ", rootObject.also_known_as);

            return(View(theMovieDb));
        }
        public void SSG_Person_should_map_to_ResponsePerson_correctly()
        {
            SSG_Person person = new SSG_Person
            {
                DateOfDeath     = new DateTime(2015, 1, 1),
                GenderOptionSet = GenderType.Other.Value,
                FirstName       = "firstName"
            };

            ResponsePerson rp = _mapper.Map <ResponsePerson>(person);

            Assert.AreEqual(new DateTimeOffset(new DateTime(2015, 1, 1)), rp.DateOfDeath);
            Assert.AreEqual("u", rp.Gender);
            Assert.AreEqual("firstName", rp.FirstName);
        }
Exemplo n.º 3
0
        public ResponseAdminUser setUser(RequestAdminUser req)
        {
            ResponseAdminUser rUser   = new ResponseAdminUser();
            ResponsePerson    rPerson = new ResponsePerson();

            try
            {
                LogicCommon com      = new LogicCommon();
                string      json     = "";
                int         idPerson = req.idPerson;
                int         idUser   = req.id;

                // Primero Registrar la persona
                if (req.flag != 'N')
                {
                    req.id = idPerson;
                }

                json    = com.HttpPost("Person/crudPerson", req);
                rPerson = JsonConvert.DeserializeObject <ResponsePerson>(json);

                if (rPerson.code == 50000)
                {
                    if (req.flag == 'N')
                    {
                        req.idPerson = rPerson.status;
                    }
                    else
                    {
                        req.id = idUser;
                    }


                    // Completar el nombre completo para el usuario
                    req.name  = req.firstName + " ";
                    req.name += req.secondName == null ? "" : req.secondName + " ";
                    req.name += req.firstLastName == null ? "" : req.firstLastName + " ";
                    req.name += req.secondLastName == null ? "" : req.secondLastName;

                    req.name = req.name.Trim();
                    // Ahora registrar el usuario
                    json  = com.HttpPost("User/adminUser", req);
                    rUser = JsonConvert.DeserializeObject <ResponseAdminUser>(json);

                    // Revertir perfil de la persona, ya que no fue posible crear el usuario
                    if (rUser.code != 50000)
                    {
                    }
                }
                else
                {
                    rUser.code    = -1;
                    rUser.message = "Error creando el perfil de la persona, favor contactar con el administrador del sistema";
                }

                return(rUser);
            }
            catch (Exception ex)
            {
                rUser.code    = -1;
                rUser.message = ex.Message;
            }

            return(rUser);
        }