Ejemplo n.º 1
0
        public async Task <IActionResult> Identification([FromBody] Identity inputData)
        {
            var identity = await _identificationService.CheckIdentity(inputData.Email, inputData.Password);

            if (identity == null)
            {
                return(_loggedRequestsService.BadLoggedRequest("Invalid username or password."));
            }
            var responce = new
            {
                token  = _createTokenService.CreateToken(identity.Claims),
                id     = identity.Claims.First(a => a.Type == "Id").Value,
                access = identity.Claims.First(a => a.Type == "Access").Value
            };

            return(Ok(responce.ToJson()));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Orders()
        {
            if (!_accessService.IsAdmin(User))
            {
                return(BadRequest("No access"));
            }
            try
            {
                var orders = await _orderService.GetOrders();

                return(Ok(orders));
            }
            catch (Exception e)
            {
                return(_loggedRequestsService.BadLoggedRequest(e.ToString()));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Clients()
        {
            if (!_accessService.IsAdmin(User))
            {
                return(BadRequest("No access"));
            }
            try
            {
                var clients = await _clientService.GetClients();

                return(Ok(clients));
            }
            catch (Exception e)
            {
                return(_loggedRequestsService.BadLoggedRequest(e.ToString()));
            }
        }
Ejemplo n.º 4
0
 public async Task <IActionResult> Products(string name = null, string category = null)
 {
     try
     {
         IList <Product> products;
         if ((name != null) || (category != null))
         {
             products = await _productService.GetProducts(name, category);
         }
         else
         {
             products = await _productService.GetProducts();
         }
         return(Ok(products));
     }
     catch (Exception e)
     {
         return(_loggedRequestsService.BadLoggedRequest(e.ToString()));
     }
 }