public ResponseResult<Report> Put(Report value)
 {
     Report report;
     var response = Request.CreateResponse<Report>(HttpStatusCode.Created, value);
     using (var lostAndFoundService = new LostAndFoundService())
     {
         report = lostAndFoundService.GetReportById(ObjectId.Parse(value._id));
         if (report != null)
         {
             report = Mapper.Map(value, report);
             lostAndFoundService.UpdateReport(report);
             return new ResponseResult<Report>
             {
                 Messages = new List<string>() { "OK" },
                 Result = report,
                 Succeed = true
             };
         }
         else
         {
             return new ResponseResult<Report>
             {
                 Result = value,
                 Succeed = false,
                 Errors = new List<string>() { "Report could not be found" }
             };
         }
     }
 }
 public IHttpActionResult Put(Report value)
 {
     Report report;
     var response = Request.CreateResponse<Report>(HttpStatusCode.Created, value);
     using (var reportsService = new ReportsService())
     {
         report = reportsService.GetById(value._id);
         if (report != null)
         {
             report = Mapper.Map(value, report);
             reportsService.Update(report);
             return Ok(report);
         }
         else
         {
             return BadRequest("Report could not be found");
         }
     }
 }
Пример #3
0
        //[TestMethod]
        //public async Task GetPaged()
        //{
        //    HttpResponseMessage response = client.GetAsync("lnf/reports/page/1").Result;
        //    Assert.IsTrue(response.IsSuccessStatusCode);
        //    Assert.IsNotNull(response.Content);

        //    var reportsString = await response.Content.ReadAsStringAsync();
        //    var reports = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(reportsString);
        //    //No puedo hacer el cast a Report porque marca error al deserializar la interfaz IReportDetail
        //    Assert.IsTrue(reports != null);
        //    Assert.IsTrue(reports.Count > 0);
        //}

        //[TestMethod]
        //public async Task GetPaged()
        //{
        //    HttpResponseMessage response = client.GetAsync("lnf/reports/page/1").Result;
        //    Assert.IsTrue(response.IsSuccessStatusCode);
        //    Assert.IsNotNull(response.Content);

        //    var reportsString = await response.Content.ReadAsStringAsync();
        //    var reports = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(reportsString);
        //    //No puedo hacer el cast a Report porque marca error al deserializar la interfaz IReportDetail
        //    Assert.IsTrue(reports != null);
        //    Assert.IsTrue(reports.Count > 0);
        //}

        //[TestMethod]
        //public async Task GetPaged()
        //{
        //    HttpResponseMessage response = client.GetAsync("lnf/reports/page/1").Result;
        //    Assert.IsTrue(response.IsSuccessStatusCode);
        //    Assert.IsNotNull(response.Content);

        //    var reportsString = await response.Content.ReadAsStringAsync();
        //    var reports = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(reportsString);
        //    //No puedo hacer el cast a Report porque marca error al deserializar la interfaz IReportDetail
        //    Assert.IsTrue(reports != null);
        //    Assert.IsTrue(reports.Count > 0);
        //}

        //[TestMethod]
        //public async Task GetPaged()
        //{
        //    HttpResponseMessage response = client.GetAsync("lnf/reports/page/1").Result;
        //    Assert.IsTrue(response.IsSuccessStatusCode);
        //    Assert.IsNotNull(response.Content);

        //    var reportsString = await response.Content.ReadAsStringAsync();
        //    var reports = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(reportsString);
        //    //No puedo hacer el cast a Report porque marca error al deserializar la interfaz IReportDetail
        //    Assert.IsTrue(reports != null);
        //    Assert.IsTrue(reports.Count > 0);
        //}

        //[TestMethod]
        //public async Task GetPaged()
        //{
        //    HttpResponseMessage response = client.GetAsync("lnf/reports/page/1").Result;
        //    Assert.IsTrue(response.IsSuccessStatusCode);
        //    Assert.IsNotNull(response.Content);

        //    var reportsString = await response.Content.ReadAsStringAsync();
        //    var reports = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(reportsString);
        //    //No puedo hacer el cast a Report porque marca error al deserializar la interfaz IReportDetail
        //    Assert.IsTrue(reports != null);
        //    Assert.IsTrue(reports.Count > 0);
        //}

        //[TestMethod]
        //public async Task GetPaged()
        //{
        //    HttpResponseMessage response = client.GetAsync("lnf/reports/page/1").Result;
        //    Assert.IsTrue(response.IsSuccessStatusCode);
        //    Assert.IsNotNull(response.Content);

        //    var reportsString = await response.Content.ReadAsStringAsync();
        //    var reports = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(reportsString);
        //    //No puedo hacer el cast a Report porque marca error al deserializar la interfaz IReportDetail
        //    Assert.IsTrue(reports != null);
        //    Assert.IsTrue(reports.Count > 0);
        //}

        //[TestMethod]
        //public async Task GetPaged()
        //{
        //    HttpResponseMessage response = client.GetAsync("lnf/reports/page/1").Result;
        //    Assert.IsTrue(response.IsSuccessStatusCode);
        //    Assert.IsNotNull(response.Content);

        //    var reportsString = await response.Content.ReadAsStringAsync();
        //    var reports = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(reportsString);
        //    //No puedo hacer el cast a Report porque marca error al deserializar la interfaz IReportDetail
        //    Assert.IsTrue(reports != null);
        //    Assert.IsTrue(reports.Count > 0);
        //}

        

        private Report newReport(string tipo)
        {
            var report = new Report
            {
                _userId = "522e8aaf18f9bf1f64555555",
                description = "Do you see any Teletubbies in here? Do you see a slender plastic tag clipped to my shirt with my name printed on it? Do you see a little Asian child with a blank expression on his face sitting outside on a mechanical helicopter that shakes when you put quarters in it? No? Well, that's what you see at a toy store. And you must think you're in a toy store, because you're here shopping for an infant named Jeb.",
                location = new Location { lat = "09280980980", lon = "098029834092" },
                type = "dog"
            };
            var contactInfo = new ContactInfo { address = "Conocido", email = new List<string> { "*****@*****.**" }, name = "JC", phones = new List<string> { "9999999999" } };
            switch (tipo)
            {
                case "abuse":
                    Abuse abuse = new Abuse { address = "Calle wallabe 124, La conchita", age = "2.5 yo", characteristics = "verde con motas rojas", date = DateTime.Today, name = "floppy" };
                    abuse.isAnonimous = true;
                    report.abuse = abuse;
                    break;
                case "found":
                    Found found = new Found { address = "Calle wallabe 124, La conchita", age = "2.5 yo", characteristics = "verde con motas rojas", date = DateTime.Today, name = "floppy" };
                    found.size = "mid";
                    found.breeds = new List<int>() { 1, 2 };
                    report.found = found;
                    break;
                case "lost":
                    var lost = new Lost { address = "Calle wallabe 124, La conchita", age = "2.5 yo", characteristics = "verde con motas rojas", date = DateTime.Today, name = "floppy" };
                    lost.reward = true;
                    lost.size = "large";
                    lost.breeds = new List<int>() { 1, 2 };
                    report.lost = lost;
                    break;
                case "resque":
                    var resque = new Resque { address = "Calle wallabe 124, La conchita", age = "2.5 yo", characteristics = "verde con motas rojas", date = DateTime.Today, name = "floppy" };
                    resque.contactInfo = contactInfo;
                    report.resque = resque;
                    break;
            }

            return report;
        }