Esempio n. 1
0
        public async Task CreateLocationAsync_PassedValidObject_ReturnsObject()
        {
            //Arrange
            var oldLocation = new Location()
            {
                ReservationId = 1
            };
            var locationDto = new LocationCreateDto()
            {
                ReservationId = 1
            };

            mockLocationRepository
            .Setup(p => p
                   .GetActualLocationByReservationIdAsync(oldLocation.ReservationId))
            .ReturnsAsync(oldLocation);
            mockLocationRepository
            .Setup(s => s.SaveChangesAsync())
            .Verifiable();
            var service = new LocationService(mockLocationRepository.Object, mapper);
            //Act
            var newLocation = await service.CreateLocationAsync(locationDto);

            //Assert
            Assert.Equal(newLocation.ReservationId, locationDto.ReservationId);
            Assert.Equal(newLocation.LocationId, oldLocation.LocationId);
            Assert.True(newLocation.IsActual);
            Assert.False(oldLocation.IsActual);
            Assert.IsType <LocationDto>(newLocation);
        }
Esempio n. 2
0
        public LocationReadDto CreateLocation(LocationCreateDto obj)
        {
            var model = _mapper.Map <Location>(obj);

            _repository.Insert(model);
            _repository.SaveChanges();

            return(_mapper.Map <LocationReadDto>(model));
        }
        public void Execute(LocationCreateDto request)
        {
            _validator.ValidateAndThrow(request);

            var location = _mapper.Map <Location>(request);

            _context.Locations.Add(location);

            _context.SaveChanges();
        }
        public async Task <IActionResult> Create(LocationCreateDto categoryDto)
        {
            if (await _categoryService.CheckExists(categoryDto.ID))
            {
                return(BadRequest("Location ID already exists!"));
            }
            //var username = User.FindFirst(ClaimTypes.Name).Value;
            //categoryIngredientDto.Updated_By = username;
            if (await _categoryService.Add(categoryDto))
            {
                return(NoContent());
            }

            throw new Exception("Creating the category failed on save");
        }
        //Thêm Brand mới vào bảng Location
        public async Task <bool> Add(LocationCreateDto model)
        {
            try
            {
                var cat = _mapper.Map <Location>(model);
                _repoLocation.Add(cat);
                await _repoLocation.SaveAll();

                var langs = model.Langs.Select(x => new LocationLang {
                    LocationID = cat.Number, Name = x.Name, LanguageID = x.LanguageID
                }).ToList();
                await _repoLocation.AddLocationLang(langs);

                await _repoLocation.SaveAll();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 6
0
        public IActionResult CreateTrail([FromBody] LocationCreateDto trailDto)
        {
            if (trailDto == null)
            {
                return(BadRequest(ModelState));
            }

            if (_npRepo.TrailExist(trailDto.Name))
            {
                ModelState.AddModelError("", "Trail already exist");
                return(StatusCode(404, ModelState));
            }

            var trailObj = _mapper.Map <Trail>(trailDto);

            if (!_npRepo.CreateTrail(trailObj))
            {
                ModelState.AddModelError("", $"Something went wrong when saving the record {trailObj.Name}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetTrail", new { trailId = trailObj.Id }, trailObj));
        }
Esempio n. 7
0
        /// <summary>
        /// Create new location. The flag IsActual of last saved location is changed to false (if exists).
        /// </summary>
        /// <param name="locationCreateDto"></param>
        /// <returns>Returns new location mapped to locationDto</returns>
        public async Task <LocationDto> CreateLocationAsync(LocationCreateDto locationCreateDto)
        {
            var oldLocation = await locationRepository.GetActualLocationByReservationIdAsync(locationCreateDto.ReservationId);

            if (oldLocation != null)
            {
                oldLocation.IsActual = false;
            }

            Location location = new Location()
            {
                ReservationId = locationCreateDto.ReservationId,
                Latitude      = locationCreateDto.Latitude,
                Longitude     = locationCreateDto.Longitude,
                IsActual      = true,
                DateCreated   = DateTime.Now
            };

            locationRepository.Create(location);
            await locationRepository.SaveChangesAsync();

            return(mapper.Map <LocationDto>(location));
        }
Esempio n. 8
0
 public IActionResult Post([FromBody] LocationCreateDto dto, [FromServices] ICreateLocationCommand command)
 {
     _executor.ExecuteCommand(command, dto);
     return(Ok("Uneto"));
 }
Esempio n. 9
0
        public async Task <IActionResult> CreateLocationAsync(LocationCreateDto locationDto)
        {
            var location = await locationService.CreateLocationAsync(locationDto);

            return(Ok(location));
        }
        public IActionResult CreateLocation([FromBody] LocationCreateDto model)
        {
            var result = _services.CreateLocation(model);

            return(CreatedAtRoute(nameof(GetLocationById), new { Id = result.LocationId }, result));
        }
 public Task <bool> Update(LocationCreateDto model)
 {
     throw new NotImplementedException();
 }