示例#1
0
 public bool AddTravel(TravelInfoDTO travel)
 {
     try
     {
         _repository.AddTravel(travel);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
        public void AddTravelTest()
        {
            var travel = new Travel
            {
                Name = "My Travel"
            };

            Assert.AreEqual(null, _repository.GetTravel(travel.Id));
            _repository.AddTravel(travel);
            Assert.AreEqual(travel, _repository.GetTravel(travel.Id));
        }
示例#3
0
        public IActionResult Post([FromBody] AddUserParam param)
        {
            if (ModelState.IsValid)
            {
                _userRepository.AddUser(param);
                var userId = _userRepository.GetAll().Max(u => u.Id);
                _travelRepository.AddTravel(userId, param.VisitedCountries);

                var userToView = new UserDto
                {
                    Id               = userId,
                    FirstName        = param.FirstName,
                    LastName         = param.LastName,
                    VisitedCountries = param.VisitedCountries
                };
                return(Ok(userToView));
            }
            else
            {
                return(BadRequest());
            }
        }