示例#1
0
        public async void LocationRouteIsAddedIntoOptedOutLocationRouteList_ValidSubscriberID_LocationRouteIsAdded()
        {
            _webApp.Load(_webApp.DBContext);

            //setting up login token
            var StringContent            = new StringContent(JsonConvert.SerializeObject(admin), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _client.PostAsync("api/Admins", StringContent);

            string adminToken = await response.Content.ReadAsStringAsync();

            _client.SetBearerToken(adminToken);

            Subscriber dbSubscriber = _webApp.DBContext.Subscriber.Where(s => s.email.Contains("hunter2@")).FirstOrDefault();

            Assert.NotNull(dbSubscriber);

            response = await _client.GetAsync("api/Subscribers/optoutID=" + dbSubscriber.subscriberID);

            string responseString = await response.Content.ReadAsStringAsync();

            //Subscriber
            Subscriber subscriber = JsonConvert.DeserializeObject <Subscriber>(responseString);
            //Location
            Location location = _webApp.DBContext.Location.FirstOrDefault(x => x.locationID == subscriber.locationID);
            //Region
            Region region = _webApp.DBContext.Region.FirstOrDefault(x => x.regionID == location.regionID);
            //Route
            Route route = _webApp.DBContext.Route.FirstOrDefault(x => x.regionID == region.regionID && !x.completed && !x.inactive);
            //LocationRoute
            LocationRoute locationRoute = _webApp.DBContext.LocationRoute.FirstOrDefault(x => x.routeID == route.routeID && x.locationID == location.locationID);

            //Ensure locationRoute is added to optoutLocationRouteList
            Assert.Contains <LocationRoute>(locationRoute, route.optoutLocationRouteList);
        }
示例#2
0
        public async Task <IActionResult> PutLocationRoute([FromRoute] int id, [FromBody] LocationRoute locationRoute)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(locationRoute).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LocationRouteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public ActionResult Index()
        {
            var           routes        = routeRepository.FindAll();
            LocationRoute locationRoute = new LocationRoute();

            locationRoute.Route = routes;
            return(View(locationRoute));
        }
示例#4
0
        public async Task <IActionResult> PostLocationRoute([FromBody] LocationRoute locationRoute)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.LocationRoute.Add(locationRoute);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLocationRoute", new { id = locationRoute.locationRouteID }, locationRoute));
        }
        public async Task <IActionResult> SubscriberOptOut([FromRoute] int id)
        {
            //If we failed the Authorize claims check, the response code will be set to 401
            if (this.Response.StatusCode == 401)
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id < 1)
            {
                return(NotFound());
            }

            //Get the specific subscriber with the ID
            Subscriber subscriber = _context.Subscriber.FirstOrDefault(x => x.subscriberID == id);

            //var subscriberList = _context.Subscriber.Include("location").Select(s => new Subscriber
            //{
            //    subscriberID = s.subscriberID,
            //    locationID = s.locationID,
            //    location = new Location
            //    {
            //        locationID = (int)s.location.locationID, regionID = s.location.regionID,
            //        region = new Region
            //        {

            //        }
            //    },
            //    billingLocation = null
            //}).Where(s => s.subscriberID == id);

            if (subscriber == null || id != subscriber.subscriberID)
            {
                return(BadRequest());
            }

            //Get the location based on the subscriber's locationID
            Location location = _context.Location.FirstOrDefault(x => x.locationID == subscriber.locationID);


            if (location == null)
            {
                return(BadRequest());
            }

            //Get the upcoming route based on the location's regionID
            Route route = _context.Route.FirstOrDefault(x => x.regionID == location.regionID && !x.completed && !x.inactive);

            //return Ok(route);

            if (route == null)
            {
                return(BadRequest());
            }

            LocationRoute locationRoute = new LocationRoute();

            locationRoute.locationID = location.locationID;
            locationRoute.routeID    = route.routeID;

            //Returns true if properly removed, otherwise false
            //_context.Configuration.LazyLoadingEnabled = false;
            _context.Route.Include("optoutLocationRouteList").FirstOrDefault <Route>(x => x.routeID == route.routeID).optoutLocationRouteList.Add(locationRoute);


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SubscriberExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            List <Subscriber> obList = new List <Subscriber>();

            obList.Add(subscriber);
            subscriber = obList.Select(s => new Subscriber
            {
                subscriberID = s.subscriberID,
                locationID   = s.locationID,
                location     = new Location
                {
                    locationID = s.location.locationID,
                    regionID   = s.location.regionID,
                    optoutLocationRouteList = s.location.optoutLocationRouteList
                                              .Select(o => new LocationRoute {
                        locationRouteID = o.locationRouteID, locationID = o.locationID, routeID = o.routeID
                    }).ToList()
                }
            }).ToList()[0];

            return(Ok(subscriber));
        }