コード例 #1
0
 //GET: api/Users
 public IHttpActionResult GetUsers()
 {
     try
     {
         if (validator.validate((Request.Headers.GetValues("Authorization").FirstOrDefault()), UserRole.Administrator))
         {
             IEnumerable <User> Users = UserService.GetAllUsers();
             return(Ok(Users));
         }
         else
         {
             return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No posee los permisos necesarios")));
         }
     }
     catch (InvalidOperationException)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Debe ingresar el header Authorization")));
     }
 }
コード例 #2
0
        public IHttpActionResult PostBill(Bill bill)
        {
            try
            {
                if (validator.validate((Request.Headers.GetValues("Authorization").FirstOrDefault()), UserRole.Administrator) ||
                    validator.validate((Request.Headers.GetValues("Authorization").FirstOrDefault()), UserRole.Cashier))
                {
                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }

                    int billId = billService.CreateBill(bill);

                    return(Ok(billId));
                }
                else
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No posee los permisos necesarios")));
                }
            }
            catch (InvalidOperationException)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Debe ingresar el header Authorization")));
            }
        }
コード例 #3
0
        public IHttpActionResult PostSupplier(Supplier supplier)
        {
            try
            {
                if (validator.validate((Request.Headers.GetValues("Authorization").FirstOrDefault()), UserRole.Administrator))
                {
                    if (!ModelState.IsValid)
                    {
                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Datos mal ingresados")));
                    }
                    try
                    {
                        int supplierId = supplierService.CreateSupplier(supplier);

                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.OK, "" + supplierId)));
                    }
                    catch (NotUniqueException ex)
                    {
                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
                    }
                    catch (InvalidCommissionException ex)
                    {
                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
                    }
                    catch (NotEnoughDataException ex)
                    {
                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
                    }
                    catch (Exception ex)
                    {
                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
                    }
                }
                else
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No posee los permisos necesarios")));
                }
            }catch (InvalidOperationException)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Debe ingresar el header Authorization")));
            }
        }
コード例 #4
0
        public IHttpActionResult PostTransaction(TransactionDTO transaction)
        {
            try
            {
                if (validator.validate((Request.Headers.GetValues("Authorization").FirstOrDefault()), UserRole.Administrator) ||
                    validator.validate((Request.Headers.GetValues("Authorization").FirstOrDefault()), UserRole.Cashier))
                {
                    try
                    {
                        if (!ModelState.IsValid)
                        {
                            return(BadRequest(ModelState));
                        }

                        int transactionId = transactionService.CreateTransaction(transaction);

                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.OK, "" + transactionId)));
                    }
                    catch (DateFormatException ex)
                    {
                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
                    }
                    catch (Exception ex)
                    {
                        return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
                    }
                }
                else
                {
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No posee los permisos necesarios")));
                }
            }
            catch (InvalidOperationException)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Debe ingresar el header Authorization")));
            }
        }