public async Task <IActionResult> PutVehicle([FromRoute] int id, [FromBody] Vehicle vehicle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != vehicle.VehicleId)
            {
                return(BadRequest());
            }

            _context.Entry(vehicle).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VehicleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] Roadtrip roadtrip)

        {
            var email = User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value;

            var user = _context.Users
                       .Where(x => x.Email == email)
                       .Include(x => x.UserRoadtrips)
                       .FirstOrDefault();

            foreach (Roadtrip ongoingRoadtripsCheck in user.UserRoadtrips)
            {
                if (ongoingRoadtripsCheck.ongoingRoadtrip == true)
                {
                    return(NotAcceptable());
                }
            }



            //var roadtriptiime = _context.Roadtrip.OrderByDescending(x => x.Date).Take(1).ToList();


            //if (roadtrip.RoadtripMilesStart < roadtriptiime.FirstOrDefault().RoadtripMilesStop)
            //{
            //    return NotAcceptable();
            //}


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


            _context.Roadtrip.Add(roadtrip);

            user.UserRoadtrips.Add(roadtrip);

            _context.Entry(user).State = EntityState.Modified;

            await _context.SaveChangesAsync();


            return(Ok(user.UserRoadtrips.ToList()));
        }