Exemplo n.º 1
0
        public ActionResult <JsonResult> Post([FromBody] mappingsrequest mappings)
        {
            if (!this.checkClient())
            {
                return(Unauthorized());
            }
            if (mappings.title_ids.Count > 10)
            {
                return(BadRequest(new Dictionary <string, object> {
                    { "data", null }, { "error", "Too many title ids (" + mappings.title_ids.Count.ToString() + "). The maximum is 10." }
                }));
            }
            List <Dictionary <string, object> > tmpmappings = new List <Dictionary <string, object> >();
            List <object> failedtitleids = new List <object>();

            foreach (object titleid in mappings.title_ids)
            {
                TitleIdMapping mapping = new TitleIdMapping(mappings.service, mappings.media_type, titleid is int?((int)titleid).ToString() : titleid is long?((long)titleid).ToString() :  (string)titleid, this.dbsettings);
                if (!mapping.errored)
                {
                    mapping.performLookup();
                    if (mapping.errored || mapping.notfound)
                    {
                        mapping.Dispose();
                        failedtitleids.Add(titleid);
                    }
                    else
                    {
                        mapping.Dispose();
                        tmpmappings.Add(mapping.generatemapdictionary());
                    }
                }
                else
                {
                    mapping.Dispose();
                    return(BadRequest(new Dictionary <string, object> {
                        { "data", null }, { "error", "Unable to connect to database." }
                    }));
                }
            }
            return(Ok(new Dictionary <string, object> {
                { "data", tmpmappings }, { "failed_list", failedtitleids }
            }));
        }
Exemplo n.º 2
0
        public ActionResult <JsonResult> Get(string service, string type, string id)
        {
            if (!this.checkClient())
            {
                return(Unauthorized());
            }
            TitleIdMapping mapping = new TitleIdMapping(service, type, id);

            if (!mapping.errored)
            {
                mapping.performLookup();
                if (mapping.errored)
                {
                    BadRequestObjectResult result = BadRequest(mapping.output);
                    mapping.Dispose();
                    return(result);
                }
                else if (mapping.notfound)
                {
                    NotFoundObjectResult result = NotFound(mapping.output);
                    mapping.Dispose();
                    return(result);
                }
                else
                {
                    OkObjectResult result = Ok(mapping.output);
                    mapping.Dispose();
                    return(result);
                }
            }
            else
            {
                BadRequestObjectResult result = BadRequest(mapping.output);
                mapping.Dispose();
                return(result);
            }
        }