コード例 #1
0
        public ActionResult Details(int id)
        {
            var result = (db.Trips.Select(t => t).Where(b => b.Id == id)).ToList();

            Models.Trip trip = result[0];
            return(View(trip));
        }
コード例 #2
0
        private async Task SetSelectedTrip()
        {
            var sTripFile = await storageFolder.GetFileAsync("selectedTrip.txt");

            var sTripJSON = await FileIO.ReadTextAsync(sTripFile);

            selectedTrip = JsonConvert.DeserializeObject <Models.Trip>(sTripJSON);
        }
コード例 #3
0
 public IActionResult Post([FromBody] Models.Trip value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _context.Trips.Add(value);
     _context.SaveChanges();
     return(Ok());
 }
コード例 #4
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] Models.Trip value)
        {
            if (context.Trips.Any(t => t.Id == id))
            {
                return(NotFound());
            }
            context.Update(value);
            await context.SaveChangesAsync();

            return(Ok());
        }
コード例 #5
0
        public IActionResult My()
        {
            var trips = new Models.Trip[] {
                new Models.Trip {
                    Description = "New York"
                },
                new Models.Trip {
                    Description = "Las Vegas"
                }
            };

            return(Json(trips));
        }
コード例 #6
0
        //more like update
        public async Task <IActionResult> PutAsync(int id, [FromBody] Models.Trip value)
        {
            if (!_context.Trips.Any(x => x.Id == id))
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _context.Trips.Update(value);
            await _context.SaveChangesAsync();

            return(Ok());
        }
コード例 #7
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] Models.Trip value)
        {
            //var  tripFromDb = _context.Trips.Find(id);
            //tripFromDb.Name = value.Name;
            //tripFromDb.StartDate = value.StartDate;
            if (!_context.Trips.Any(t => t.Id == id))
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Trips.Update(value);
            await _context.SaveChangesAsync();

            return(Ok());
        }
コード例 #8
0
ファイル: DefaultApi.cs プロジェクト: gplumb/CertainSix
        public virtual IActionResult CreateTrip([FromBody] TripCreationDetails tripCreationDetails)
        {
            var trip = _repo.Trips.FirstOrDefault(x => x.Name.Equals(tripCreationDetails.Name));

            if (trip != null)
            {
                return(StatusCode(400));
            }

            trip = new Models.Trip()
            {
                Name             = tripCreationDetails.Name,
                SpoilDuration    = tripCreationDetails.SpoilDuration,
                SpoilTemperature = tripCreationDetails.SpoilTemperature
            };

            _repo.Trips.Add(trip);
            _repo.SaveChanges();

            Response.Headers.Add("Location", new Microsoft.Extensions.Primitives.StringValues($"/trips/{trip.Id}"));
            return(StatusCode(201));
        }
コード例 #9
0
 public DetailTripViewModel(Models.Trip trip)
 {
 }
コード例 #10
0
 public void Put(int id, [FromBody] Models.Trip value)
 {
     _repository.Update(value);
 }
コード例 #11
0
 public void Post([FromBody] Models.Trip value)
 {
     _repository.Add(value);
 }
コード例 #12
0
 // PUT api/<controller>/5
 public void Put(int id, [FromBody] Models.Trip value)
 {
     _Repo.Update(id, value);
 }
コード例 #13
0
 // POST api/<controller>
 public void Post([FromBody] Models.Trip value)
 {
     _Repo.Add(value);
 }
コード例 #14
0
        private async void FinishTrip()
        {
            var odometer = int.Parse(txtOdometer.Text);
            var fuel     = int.Parse(txtFuel.Text);

            StorageFile currentTripFile = await storageFolder.GetFileAsync("CurrentTrip.txt");

            var JsonString = await FileIO.ReadTextAsync(currentTripFile);

            var currentTripValues = JsonConvert.DeserializeObject <Models.CurrentTrip>(JsonString);

            if (odometer > currentTripValues.Odometer && fuel < currentTripValues.Fuel)
            {
                ContentDialog FinishCurrentTripDialog = new ContentDialog
                {
                    Title             = "FINISHING CURRENT TRIP!",
                    Content           = "Do you really want to finish your current trip?",
                    CloseButtonText   = "NO",
                    PrimaryButtonText = "YES"
                };

                ContentDialogResult result = await FinishCurrentTripDialog.ShowAsync();

                if (result == ContentDialogResult.Primary)
                {
                    StorageFile TripsFile = await storageFolder.GetFileAsync("Trips.txt");

                    var JsonTrips = await FileIO.ReadTextAsync(TripsFile);


                    List <Models.Trip> trips;
                    int number;
                    try
                    {
                        trips  = JsonConvert.DeserializeObject <List <Models.Trip> >(JsonTrips);
                        number = 0;
                        foreach (var t in trips)
                        {
                            if (t.Number > number)
                            {
                                number = t.Number;
                            }
                        }
                        number++;
                    }
                    catch
                    {
                        trips  = new List <Models.Trip>();
                        number = 1;
                    }
                    var distance    = (double)odometer - (double)currentTripValues.Odometer;
                    var usedFuel    = (double)currentTripValues.Fuel - (double)fuel;
                    var consumption = $"{Math.Round(usedFuel/(distance/100), 2)} {currentTripValues.FUnit}/100{currentTripValues.OUnit}";
                    var moneySpent  = $"{currentTripValues.FPrice} {currentTripValues.Currency}";

                    var trip = new Models.Trip
                    {
                        Number      = number,
                        Vehicle     = currentTripValues.Vehicle,
                        Distance    = (int)distance,
                        Odometer    = odometer,
                        OUnit       = currentTripValues.OUnit,
                        UsedFuel    = (int)usedFuel,
                        FUnit       = currentTripValues.FUnit,
                        FType       = currentTripValues.FType,
                        Consumption = consumption,
                        MoneySpent  = moneySpent
                    };

                    trips.Add(trip);

                    var tripsJSON = JsonConvert.SerializeObject(trips);

                    await FileIO.WriteTextAsync(TripsFile, tripsJSON);

                    ClearCurrentTrip();
                    Frame.Navigate(typeof(Views.Diary));
                }
            }
            else
            {
                ContentDialog IncorrectDataDialog = new ContentDialog
                {
                    Title           = "Incorrect data!",
                    Content         = "Fuel at the end of the trip must be less then this at the beggining or\nOdometer at the end of the trip must be more than this at the beggining!",
                    CloseButtonText = "OK"
                };

                ContentDialogResult result = await IncorrectDataDialog.ShowAsync();
            }
        }