public ActionResult Create(TripPostModel model) { var tripModel = _mapper.Map <TripModel>(model); _tripService.Create(tripModel); return(RedirectToAction("Create", "Trip")); }
public IActionResult Create(TripCreate model) { if (!ModelState.IsValid) { return(BadRequest()); } _tripService.Create(model, User.FindFirst(ClaimTypes.NameIdentifier).Value); return(Ok()); }
public void CreateTest() { _tripService.Create(new Models.Trip.TripCreate { Country = "testnew", }, "123"); var art = _context.Trips.FirstOrDefault(m => m.Country == "testnew"); Assert.NotNull(art); }
public IActionResult Create([FromBody] Trip trip) { if (trip != null) { _service.Create(trip); return(Ok()); } return(BadRequest("Trip creation failed.")); }
public async Task <ActionResult <Db.Trip> > Create([FromBody] Api.Trip trip) { if (ModelState.IsValid) { try { var tripAdded = await _tripService.Create(trip); return(Ok(tripAdded)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } else { return(BadRequest(ModelState.Values)); } }
public ActionResult Create([FromBody] Trip trip) { var currentUserPhone = User.FindFirst(ClaimTypes.MobilePhone)?.Value; var user = _userService.Find(currentUserPhone); trip.Driver = user; var result = _tripService.Create(trip); if (result) { return(Ok(new ResponseModel { Message = "Trip created successfully", })); } return(BadRequest(new ResponseModel { Message = "Bad request" })); }
public async Task <IActionResult> Create([FromBody] TripDetailModel model) { var id = await _tripService.Create(Mapper.Map <Trip>(model)); return(Ok(id)); }
public HttpResponse Add(AddBindingModel input) { if (!IsUserLoggedIn()) { return(Redirect("/Home/Index")); } if (string.IsNullOrEmpty(input.StartPoint) || string.IsNullOrWhiteSpace(input.StartPoint)) { return(Redirect("/Trips/Add")); } if (string.IsNullOrEmpty(input.EndPoint) || string.IsNullOrWhiteSpace(input.EndPoint)) { return(Redirect("/Trips/Add")); } if (string.IsNullOrEmpty(input.DepartureTime) || string.IsNullOrWhiteSpace(input.DepartureTime)) { return(Redirect("/Trips/Add")); } if (string.IsNullOrEmpty(input.Description) || string.IsNullOrWhiteSpace(input.Description) || input.Description.Length > 80) { return(Redirect("/Trips/Add")); } if (input.Seats < 2 || input.Seats > 6) { return(Redirect("/Trips/Add")); } var dateTimeParsed = new DateTime(); if (!DateTime.TryParse(input.DepartureTime, out dateTimeParsed)) { var dateArgs = input.DepartureTime.Split('.').ToList(); var day = int.Parse(dateArgs[0]); var month = int.Parse(dateArgs[1]); var timeArgs = dateArgs[2].Split(' ').ToList(); var year = int.Parse(timeArgs[0]); var hourArgs = timeArgs[1].Split(':').ToList(); var hour = int.Parse(hourArgs[0]); var minutes = int.Parse(hourArgs[1]); var date = new DateTime(year, month, day, hour, minutes, 0); var trip = new TripServiceModel { StartPoint = input.StartPoint, EndPoint = input.EndPoint, Seats = input.Seats, Description = input.Description, ImagePath = input.ImagePath, DepartureTime = date }; tripService.Create(trip); } else { var trip = new TripServiceModel { StartPoint = input.StartPoint, EndPoint = input.EndPoint, Seats = input.Seats, Description = input.Description, ImagePath = input.ImagePath, DepartureTime = dateTimeParsed }; tripService.Create(trip); } return(this.Redirect("/Trips/All")); }
public IActionResult Create(long carId, [FromBody] TripViewModel trip) { return(Ok(_tripService.Create(carId, trip).ToViewModel())); }