예제 #1
0
        public async Task <IActionResult> ClearReservation(string requestToken, [FromForm] Reservation requestReservation)
        {
            if (!_context.ValidateAdminToken(requestToken))
            {
                return(Unauthorized());
            }

            var existing = _context.GetReservation(requestReservation.Port);

            if (existing == null)
            {
                return(Ok("Port is not reserved"));
            }

            //Validate the requested reservation
            if (requestReservation.ReservedFor == null)
            {
                requestReservation.ReservedFor = _context.GetToken(requestReservation.Token);
            }
            if (requestReservation.ReservedFor == null)
            {
                return(Problem("The user this reservation is for does not exist"));
            }
            requestReservation.ApprovedBy = _context.GetToken(requestToken);

            await _context.SaveChangesAsync();

            _context.Add(requestReservation);
            requestReservation.ApprovedBy  = null;
            requestReservation.ReservedFor = null;
            return(Ok(requestReservation));
        }
예제 #2
0
        public async Task <ActionResult <Token> > CreateUserToken(string requestToken, [FromForm] Token t)
        {
            if (!_context.ValidateAdminToken(requestToken))
            {
                return(this.Unauthorized());
            }

            if (string.IsNullOrEmpty(t.Owner))
            {
                return(this.Problem("Missing owner"));
            }
            if (string.IsNullOrEmpty(t.Class))
            {
                return(this.Problem("Missing class"));
            }
            var token = Token.CreateUser(t.Owner, t.Class);

            _context.Add(token);
            await _context.SaveChangesAsync();

            return(Ok(token));
        }