Esempio n. 1
0
        public IActionResult PostTrip([FromBody] PlannedTripRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var newTrip = _service.CreateTrip(request);

            return(CreatedAtRoute("GetTrip", new { tripId = newTrip.Id }, request));
        }
Esempio n. 2
0
        public async Task <ActionResult> CreateTrip(int creatorId, [FromBody] TripCreateDTO newTrip)
        {
            try
            {
                TripDTO result = await _tripService.CreateTrip(creatorId, newTrip);

                if (result != null)
                {
                    return(Ok(result));
                }
                return(BadRequest(new JsonResult("Trip dates are not valid.")));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 3
0
        public IHttpActionResult CreateTrip([FromBody] CreateTripViewModel request)
        {
            string username = Utilities.GetUserNameFromRequest(Request);

            if (username == null)
            {
                return(BadRequest("Access Denied"));
            }

            CreateTripViewModelResponse response = new CreateTripViewModelResponse()
            {
                Status_code = "200",
                Message     = "OK",
                Earning     = 0,
                NumberOrder = 0,
            };

            try
            {
                request.FromDate.Replace("%2F", "/");
                request.ToDate.Replace("%2F", "/");
                string userId = _userService.GetUsers().Where(u => u.UserName.Equals(username)).FirstOrDefault()?.Id;
                Trip   trip   = new Trip()
                {
                    UserId     = userId,
                    FromCityId = _cityService.GetCities().FirstOrDefault(c => c.Code.Equals(request.FromCityGeonameId)).Id,
                    ToCityId   = _cityService.GetCities().FirstOrDefault(c => c.Code.Equals(request.ToCityGeonameId)).Id,
                    FromDate   = DateTime.ParseExact(request.FromDate, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    ToDate     = DateTime.ParseExact(request.ToDate, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    Name       = ""
                };
                _tripService.CreateTrip(trip);
                _tripService.SaveTrip();
                response.TripId      = trip.Id;
                response.DateCreated = trip.DateCreated.GetValueOrDefault().ToString("dd/MM/yyyy");
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }

            return(Ok(response));
        }
Esempio n. 4
0
        public IActionResult Create(TripViewModel trip)
        {
            var currentUserName = User.Identity.Name;
            var userId          = _userManagerService.GetUserByName(currentUserName);

            if (ModelState.IsValid)
            {
                if (trip.TripImg != null)
                {
                    byte[] imageData = null;
                    using (var binaryReader = new BinaryReader(trip.TripImg.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)trip.TripImg.Length);
                    }
                    _tripService.CreateTrip(trip, userId.Result.Id, imageData);
                    return(RedirectToAction("Index"));
                }
            }
            return(View(trip));
        }
Esempio n. 5
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            [ServiceBus("TripRequested", Connection = "ScooterServiceBusConnection")] IAsyncCollector <Message> tripRequested,
            ClaimsPrincipal claimPrincipals,
            ILogger log)
        {
            log.LogInformation("Create TripDocument triggered...");

            var riderClaims = claimPrincipals.ToRiderClaims();

            if (riderClaims == null)
            {
                return(new BadRequestErrorMessageResult("User is not authorized"));
            }

            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var tripRequest = JsonConvert.DeserializeObject <TripRequest>(requestBody);

            try
            {
                //TODO: Validate TripDocument Request if the ScooterDocument is free!

                // create a new TripDocument in Trip Collection db
                var trip = await _tripService.CreateTrip(tripRequest, riderClaims);

                // Add TripRequested event to service bus Topic
                var message = trip.ToMessage(trip.ScooterCode);
                await tripRequested.AddAsync(message);

                return(new OkObjectResult(trip));
            }
            catch (Exception e)
            {
                var error = $"CreateTrip failed: {e.Message}";
                log.LogError(error);
                return(new BadRequestObjectResult(error));
            }
        }
Esempio n. 6
0
 public void AddTrip(Trip trip)
 {
     _tripsService.CreateTrip(trip);
 }
Esempio n. 7
0
 public void AddTrip([FromBody] TripDto trip)
 {
     _tripsService.CreateTrip(_mapper.Map <Trip>(trip));
 }