Beispiel #1
0
        public IHttpActionResult PutLocationLookup(int id, LocationLookup locationLookup)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public IHttpActionResult GetLocationLookup(int id)
        {
            LocationLookup locationLookup = db.LocationLookups.Find(id);

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

            return(Ok(locationLookup));
        }
Beispiel #3
0
        public async Task <IHttpActionResult> PostMBL_SightDetails(SightingData postData)
        {
            try
            {
                //This is currently redundant, as user cannot enter a location on UI. They have to manually select one from the drop-down.
                int locationID;
                if (!int.TryParse(postData.locationSelected.ToString(), out locationID))
                {
                    //it's a new location, add it to location lookup
                    LocationLookup locationEntity = new LocationLookup()
                    {
                        Name                    = postData.locationSelected.ToString(),
                        GridReference           = postData.gridReference,
                        boolManuallyAddedRecord = true,
                        boolApprovedByAdmin     = false
                    };

                    db.LocationLookups.Add(locationEntity);
                    db.SaveChanges();
                    //get new location ID
                    locationID = locationEntity.LocationID;
                }

                //convert date time from web page into SQL format
                DateTime tempSightDate = Convert.ToDateTime(postData.dt);
                DateTime tempSightTime = Convert.ToDateTime(postData.myTime);

                DateTime sightDate = tempSightDate.Date;
                TimeSpan sightTime = tempSightTime.TimeOfDay;

                DateTime sightDateTime = sightDate.Date.Add(sightTime);

                var newSightDetails = new MBL_SightDetails
                {
                    SightReportUserID = postData.sightReportUserID,
                    LocationID        = locationID,
                    GridReference     = postData.gridReference,
                    SightDateTime     = sightDateTime,
                    SubmitDateTime    = DateTime.Now
                };

                db.MBL_SightDetails.Add(newSightDetails);

                await db.SaveChangesAsync();

                return(CreatedAtRoute("DefaultApi", new { id = newSightDetails.SightDetailsID }, newSightDetails));
            }
            catch (Exception ex)
            {
                var error = ex.InnerException.Message;
                return(BadRequest("Error saving Sight details - " + error));
            }
        }
Beispiel #4
0
        public IHttpActionResult PostLocationLookup(LocationLookup locationLookup)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.LocationLookups.Add(locationLookup);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = locationLookup.LocationID }, locationLookup));
        }
Beispiel #5
0
        public IHttpActionResult DeleteLocationLookup(int id)
        {
            LocationLookup locationLookup = db.LocationLookups.Find(id);

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

            db.LocationLookups.Remove(locationLookup);
            db.SaveChanges();

            return(Ok(locationLookup));
        }
Beispiel #6
0
        private List <Node> GetNodesAround(Point location)
        {
            List <Point> points = location.GetPointsAround();
            List <Node>  around = new List <Node>();

            foreach (var p in points)
            {
                Node node = null;
                if (LocationLookup.TryGetValue(p, out node))
                {
                    around.Add(node);
                }
            }
            return(around);
        }
Beispiel #7
0
        public void GetExaminations_PopulatesLookups()
        {
            // Arrange
            SetupAuthorize(AuthorizationResult.Success());
            var expectedLocation = new LocationLookup {
                LocationId = "location1", Name = "Name1"
            };
            var expectedUser = new UserLookup {
                UserId = "user1", FullName = "User 1", GmcNumber = "GmcNumber1"
            };

            var examination1 = new Examination();
            var examination2 = new Examination();
            IEnumerable <Examination> examinationsResult = new List <Examination> {
                examination1, examination2
            };
            var meOfficeLocation = new Location
            {
                LocationId = "location1",
                Name       = "Name1",
                IsMeOffice = true
            };

            var locations = new List <Location>
            {
                meOfficeLocation,
                new Location
                {
                    LocationId = "location2",
                    Name       = "Name2"
                }
            };
            var users = new List <MeUser>
            {
                new MeUser
                {
                    UserId      = "user1",
                    GmcNumber   = "GmcNumber1",
                    FirstName   = "User",
                    LastName    = "1",
                    Permissions = new List <MEUserPermission>
                    {
                        new MEUserPermission
                        {
                            LocationId = "location1",
                            UserRole   = UserRoles.MedicalExaminer
                        }
                    }
                }
            };

            var examinationOverview = new ExaminationsOverview();

            _examinationsRetrievalQueryServiceMock
            .Setup(service => service.Handle(It.IsAny <ExaminationsRetrievalQuery>()))
            .Returns(Task.FromResult(examinationsResult));

            _examinationsDashboardServiceMock
            .Setup(service => service.Handle(It.IsAny <ExaminationsRetrievalQuery>()))
            .Returns(Task.FromResult(examinationOverview));

            _locationRetrievalByQueryHandlerMock
            .Setup(service => service.Handle(It.IsAny <LocationsRetrievalByQuery>()))
            .Returns(Task.FromResult(locations.AsEnumerable()));

            _usersRetrievalServiceMock
            .Setup(service => service.Handle(It.IsAny <UsersRetrievalQuery>()))
            .Returns(Task.FromResult(users.AsEnumerable()));

            _locationsRetrievalByQueryMock.Setup(service => service.Handle(It.IsAny <LocationsParentsQuery>()))
            .Returns(Task.FromResult((IDictionary <string, IEnumerable <Location> >) new Dictionary <string, IEnumerable <Location> >
            {
                { meOfficeLocation.LocationId, new[] { meOfficeLocation } }
            }));

            var request = new GetExaminationsRequest();

            // Act
            var response = Controller.GetExaminations(request).Result;

            // Assert
            var taskResult    = response.Should().BeOfType <ActionResult <GetExaminationsResponse> >().Subject;
            var okResult      = taskResult.Result.Should().BeAssignableTo <OkObjectResult>().Subject;
            var typedResponse = (GetExaminationsResponse)okResult.Value;

            // Assert
            typedResponse.Lookups.ContainsKey(ExaminationsController.LocationFilterLookupKey).Should().BeTrue();
            typedResponse.Lookups[ExaminationsController.LocationFilterLookupKey].Should()
            .ContainEquivalentOf(expectedLocation);

            typedResponse.Lookups.ContainsKey(ExaminationsController.UserFilterLookupKey).Should().BeTrue();
            typedResponse.Lookups[ExaminationsController.UserFilterLookupKey].Should()
            .ContainEquivalentOf(expectedUser);
        }
 private static string MakeName(LocationLookup locationData, int total)
 {
     return(total != 1 && locationData.Name != locationData.County
         ? string.Format("{0} ({1})", locationData.Name, locationData.County)
         : locationData.Name);
 }