public JsonResult SendRequest(string accessToken, string startingAddressMainText, string startingAddressSecondaryText, string startingAddressLocationLat, string startingAddressLocationLng, string finishAddressMainText, string finishAddressSecondaryText, string finishAddressLocationLat, string finishAddressLocationLng) { if (HttpContext.Request.RequestType == "POST") { var newAccessToken = _accessTokenService.GenerateAccessToken(accessToken); if (newAccessToken == null) { return(Json(new { status = "INVALID ACCESSTOKEN" })); } var userId = _accessTokenService.GetUserId(newAccessToken); if (userId == null) { return(Json(new { status = "ERR1", accessToken = newAccessToken })); } var client = _clientService.GetAll().Where(x => x.UserId == userId).FirstOrDefault(); if (client == null) { return(Json(new { status = "ERR2", accessToken = newAccessToken })); } var anotherRequest = _requestService.GetClientRequest().Where(c => c.Client.Id == client.Id).FirstOrDefault(); if (anotherRequest != null) { return(Json(new { status = "ERR3", accessToken = accessToken })); } var requestInfo = new RequestInfo() { CreatedBy = CreatedBy.Client, CreatedDateTime = DateTime.Now, CreatorUserId = userId, LastModificationDateTime = DateTime.Now, RequestStatus = RequestStatusEnum.NoCarChosen, StartingAddress = startingAddressMainText + " " + startingAddressSecondaryText, FinishAddress = finishAddressMainText + " " + finishAddressSecondaryText, StartingLocation = new Models.Models.Location() { Latitude = double.Parse(startingAddressLocationLat), Longitude = double.Parse(startingAddressLocationLng) }, FinishLocation = new Models.Models.Location() { Latitude = double.Parse(finishAddressLocationLat), Longitude = double.Parse(finishAddressLocationLng) } }; _requestService.AddRequestInfo(requestInfo); var activeRequest = new ActiveRequest(); activeRequest.Request = requestInfo; activeRequest.DateTimeChosenCar = DateTime.Now; var appropriateCar = _carService.AppropriateCar(new Models.Models.Location() { Latitude = double.Parse(startingAddressLocationLat), Longitude = double.Parse(startingAddressLocationLng) }); if (appropriateCar != null) { activeRequest.AppropriateCar = appropriateCar; requestInfo.RequestStatus = RequestStatusEnum.NotTaken; _requestService.ModifyRequestInfo(requestInfo); } _requestService.AddActiveRequest(activeRequest); var clientRequest = new ClientRequest() { Client = client, Request = requestInfo }; _requestService.AddClientRequest(clientRequest); return(Json(new { accessToken = newAccessToken, status = "OK" })); } return(Json(new { })); }