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

            if (id != relRouteUser.IdRelation)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutRoutes([FromBody] Routes routes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (routes == null || routes.Id == 0)
            {
                return(BadRequest());
            }

            Boolean exist = _context.Routes.Where(o => o.Id != routes.Id && o.Route.ToLower() == routes.Route.ToLower()).Any();

            if (exist)
            {
                return(BadRequest("La ruta ya se encuentra en uso!"));
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoutesExists(routes.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        public IActionResult RegisterRouteVisit([FromBody] int id)
        {
            try
            {
                if (_context.Routes.FindAsync(id) == null)
                {
                    return(NotFound());
                }

                RouteVisit visit = new RouteVisit();
                visit.RouteId   = id;
                visit.VisitDate = DateTime.Now;
                _context.RouteVisit.Add(visit);
                _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }