Esempio n. 1
0
        private async Task <Location> EnsureLocationExistence(LocationV1DTO lDTO)
        {
            var location = await _context.Location
                           .Where(l => l.LocationName == lDTO.LocationName)
                           .SingleOrDefaultAsync();

            if (location == null)
            {
                location = new Location();

                if (lDTO.LocationTypeDTO != null)
                {
                    var ltype = await _context.LocationType
                                .Where(l => l.LocationTypeId == location.LocationTypeId)
                                .SingleOrDefaultAsync();

                    if (ltype == null)
                    {
                        ltype = new LocationType();
                        _context.LocationType.Add(ltype);
                        _context.Entry(ltype).CurrentValues.SetValues(lDTO.LocationTypeDTO);
                        await _context.SaveChangesAsync();
                    }
                    lDTO.LocationTypeId = ltype.LocationTypeId;
                }
                _context.Location.Add(location);
                _context.Entry(location).CurrentValues.SetValues(lDTO);
                await _context.SaveChangesAsync();
            }
            return(location);
        }
Esempio n. 2
0
        public async Task PutLocationAsync(LocationV1DTO locationDTO)
        {
            var location = await _context.Location
                           .Where(l => l.LocationId == locationDTO.LocationId)
                           .SingleOrDefaultAsync();

            _context.Entry(location).CurrentValues.SetValues(locationDTO);

            await _context.SaveChangesAsync();
        }
Esempio n. 3
0
        public void Location_should_not_have_errors()
        {
            var location = new LocationV1DTO();

            location.LocationName    = "a valid name";
            location.BuildingId      = "1";
            location.LocationAddress = "506 SW Mill St, Portland, OR 97201";
            location.RoomNumber      = "1";
            location.FloorNumber     = "1";
            var Result = LocationVal.TestValidate(location);


            Result.ShouldNotHaveValidationErrorFor(x => x.LocationTypeId);
            Result.ShouldNotHaveValidationErrorFor(x => x.LocationName);
            Result.ShouldNotHaveValidationErrorFor(x => x.BuildingId);
            Result.ShouldNotHaveValidationErrorFor(x => x.LocationAddress);
            Result.ShouldNotHaveValidationErrorFor(x => x.RoomNumber);
            Result.ShouldNotHaveValidationErrorFor(x => x.FloorNumber);
        }
Esempio n. 4
0
        public async Task <IActionResult> PutLocation(int locationId, [FromBody] LocationV1DTO locationDTO)
        {
            try
            {
                // Check to ensure service exists before calling contextmanager method.
                var location = await _contextManager.GetLocationByIdAsync(locationId);

                if (location == null)
                {
                    return(NotFound());
                }
                locationDTO.LocationId = locationId;

                await _contextManager.PutLocationAsync(locationDTO);

                return(NoContent());
            }
            catch (Exception e)
            {
                throw e;
            }
        }