public string GetAllContainers()
        {
            var result = "";

            using (diplomaDBContext = new DiplomaDBContext())
            {
                var containers = diplomaDBContext.Container.ToArray();

                var containersLocation = new ContainerLocation[containers.Length];
                for (int i = 0; i < containersLocation.Length; i++)
                {
                    var location = new Diploma_WebControllerAPI.ViewModels.Location
                    {
                        Latitude  = diplomaDBContext.Location.Single(l => l.Id == containers[i].LocationId).Latitude,
                        Longitude = diplomaDBContext.Location.Single(l => l.Id == containers[i].LocationId).Longitude
                    };

                    containersLocation[i] = new ContainerLocation
                    {
                        Id         = containers[i].Id,
                        Full       = containers[i].Full,
                        LastGather = containers[i].LastGather,
                        LastUpdate = containers[i].LastUpdate,
                        Region     = diplomaDBContext.Region.Single(l => l.Id == containers[i].RegionId).Name,
                        Location   = location
                    };
                }

                result = JsonSerializer.Serialize(containersLocation, JsonOptions);
            }

            Response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:3000");
            return(result);
        }
 public void AddNeighborTest()
 {
     _cl = new ContainerLocation(new Location("testContainerLocation"));
     Assert.AreEqual(_cl.Count, 0);
     _cl.AddNeighbor(new Location("testme"), Directions.Down);
     Assert.AreEqual(_cl.Count, 1);
 }
Esempio n. 3
0
        public IHttpActionResult PutContainerLocation(int id, ContainerLocation containerLocation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != containerLocation.id)
            {
                return(BadRequest());
            }

            db.Entry(containerLocation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContainerLocationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public void DeadEndTest(ContainerLocation cl)
 {
     cl = new ContainerLocation(locations);
     cl.DeadEndCheck(locations);
     Assert.IsTrue(_check.RedFlag);
     Assert.IsFalse(_check.RedFlag);
     Assert.IsFalse(_check.GreenFlag);
 }
Esempio n. 5
0
        public IHttpActionResult GetContainerLocation(int id)
        {
            ContainerLocation containerLocation = db.ContainerLocations.Find(id);

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

            return(Ok(containerLocation));
        }
Esempio n. 6
0
        public IHttpActionResult PostContainerLocation(ContainerLocation containerLocation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ContainerLocations.Add(containerLocation);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = containerLocation.id }, containerLocation));
        }
Esempio n. 7
0
        public IHttpActionResult DeleteContainerLocation(int id)
        {
            ContainerLocation containerLocation = db.ContainerLocations.Find(id);

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

            db.ContainerLocations.Remove(containerLocation);
            db.SaveChanges();

            return(Ok(containerLocation));
        }