public void TestAddJourneyValidPhotoDoesntExist() { var model = new JourneyFormViewModel { Location = "Paris", StartDate = DateTime.Now, EndDate = DateTime.Now }; var journey = _repository.AddJourney("1", model); Assert.AreEqual("Barcelona", journey.Location); }
public JourneyViewModel AddJourney(string userId, JourneyFormViewModel model) { var photoPath = GetPhotoPath(model.Location).Result; var journey = new Journey { UserId = userId, Location = model.Location, PhotoPath = photoPath, StartDate = model.StartDate, EndDate = model.EndDate }; _context.Journeys.Add(journey); _context.SaveChanges(); return(GetJourney(journey.Id)); }
public ActionResult <JourneyViewModel> CreateJourney([FromBody] JourneyFormViewModel model) { if (model.EndDate < Today) { return(StatusCode(422, "End date must not be in the past")); } if (model.StartDate.CompareTo(model.EndDate) > 0) { return(StatusCode(422, "Start date is later than end date")); } var userId = GetUserId(User); return(Ok(_journeyRepository.AddJourney(userId, model))); }