Beispiel #1
0
        public object Get(int idOrder)
        {
            //token do user logado
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);

            if (userLoggedIn != null)
            {
                //verifica se o utilizador tem alguma Encomenda
                if (OrderService.VerifyOrderAccess(userLoggedIn[0], idOrder))
                {
                    return(OrderService.GetOrderId(idOrder));
                }
                else
                {
                    return(MessageService.AccessDenied());
                }
            }
            else
            {
                List <object> msg = new List <object>()
                {
                    MessageService.AccessDenied()
                };
                return(msg);
            }
        }
        public Message Post([FromBody] Product product)
        {
            //token do user logado
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);
            //userLoggedIn[0] = Id
            //userLoggedIn[1] = UserType

            if (userLoggedIn != null)
            {
                if (userLoggedIn[1] == 2)
                {
                    return(ProductService.VerifyProduct(userLoggedIn, product, false, -1));
                }
                else
                {
                    return(MessageService.AccessDenied());
                }
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #3
0
        public List <object> GetUserOrders()
        {
            //token do user logado
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);

            if (userLoggedIn != null)
            {
                //verifica se o utilizador tem alguma Encomenda
                // o valor -1 deixa o utilizador passar para ver as suas orders
                if (OrderService.VerifyOrderAccess(userLoggedIn[0], -1))
                {
                    return(OrderService.GetOrdersUserId());
                }
                else
                {
                    List <object> msg = new List <object>()
                    {
                        MessageService.WithoutResults()
                    };
                    return(msg);
                }
            }
            else
            {
                List <object> msg = new List <object>()
                {
                    MessageService.AccessDenied()
                };
                return(msg);
            }
        }
Beispiel #4
0
        public Message Put(int idUser, [FromBody] User companyUpdate)
        {
            //token do user logado
            string token = Request.Headers["token"];

            if (token != null)
            {
                return(UserService.PutUser(token, companyUpdate, idUser));
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #5
0
        public Message Delete(int idUser)
        {
            //token do user logado
            string token = Request.Headers["token"];

            if (token != null)
            {
                return(UserService.DeleteUser(token, idUser));
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #6
0
        public object Get(int idUser)
        {
            //token do user logado
            string token = Request.Headers["token"];

            if (token != null)
            {
                //vai buscar o utilizadore
                return(UserService.GetUserId(token, idUser));
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #7
0
        public Message PutOrder(int idOrder)
        {
            //token do user com a sessão iniciada
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);

            if (userLoggedIn != null)
            {
                return(OrderService.ChangePayment(userLoggedIn, idOrder));
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #8
0
        public Message Post([FromBody] OrderProduct newOrderProduct)
        {
            //token do user com a sessão iniciada
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);

            if (userLoggedIn != null)
            {
                return(OrderService.VerifyOrder(userLoggedIn, newOrderProduct, false, -1, -1));
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #9
0
        public Message Delete(int idOrder, int idProduct)
        {
            //token do user com a sessão iniciada
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);

            if (userLoggedIn != null)
            {
                return(OrderService.DeleteOrder(userLoggedIn[0], idOrder, idProduct));
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #10
0
        public Message Put(int idDelivery, [FromBody] Delivery deliveryUpdate)
        {
            //token do user logado
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);

            if (userLoggedIn != null)
            {
                return(DeliveryService.ChangeDeliveryState(userLoggedIn[0], deliveryUpdate, idDelivery));
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #11
0
        public Message PutProduct(int idOrder, int idProduct, [FromBody] OrderProduct orderProductUpdate)
        {
            //token do user com a sessão iniciada
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);

            if (userLoggedIn != null)
            {
                return(OrderService.VerifyOrder(userLoggedIn, orderProductUpdate, true, idOrder, idProduct));
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }
Beispiel #12
0
        public object Put(int idUser, [FromBody] User clientUpdate)
        {
            //token do user logado
            string token = Request.Headers["token"];

            if (token != null)
            {
                return(UserService.PutUser(token, clientUpdate, idUser));
            }
            else
            {
                List <object> msg = new List <object>()
                {
                    MessageService.AccessDenied()
                };
                return(msg);
            }
        }
Beispiel #13
0
        public object Get(int idDelivery)
        {
            //token do user logado
            string token = Request.Headers["token"];

            if (token != null)
            {
                return(DeliveryService.GetDeliveryId(token, idDelivery));
            }
            else
            {
                List <object> msg = new List <object>()
                {
                    MessageService.AccessDenied()
                };
                return(msg);
            }
        }
Beispiel #14
0
        public object Delete(int idUser)
        {
            //token do user logado
            string token = Request.Headers["token"];

            if (token != null)
            {
                return(UserService.DeleteUser(token, idUser));
            }
            else
            {
                List <object> msg = new List <object>()
                {
                    MessageService.AccessDenied()
                };
                return(msg);
            }
        }
Beispiel #15
0
        public List <object> Get()//so pode ser acedido pelo admin
        {
            //token do user logado
            string token = Request.Headers["token"];

            if (token != null)
            {
                //vai buscar os utilizadores
                return(UserService.GetUser(token, 2));
            }
            else
            {
                List <object> msg = new List <object>()
                {
                    MessageService.AccessDenied()
                };
                return(msg);
            }
        }
Beispiel #16
0
        public List <object> Get()
        {
            //token do user logado
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);

            if (userLoggedIn != null)
            {
                return(DeliveryService.GetDeliveries(userLoggedIn));
            }
            else
            {
                List <object> msg = new List <object>()
                {
                    MessageService.AccessDenied()
                };
                return(msg);
            }
        }
Beispiel #17
0
        public Message Delete(int idProduct)
        {
            //token do user logado
            string token = Request.Headers["token"];

            int[] userLoggedIn = UserService.UserLoggedIn(token);
            //userLoggedIn[0] = Id
            //userLoggedIn[1] = UserType

            if (userLoggedIn != null)
            {
                using (var db = new DbHelper())
                {
                    if (userLoggedIn != null)
                    {
                        //procura pelo product na base de dados
                        var productsDB = db.product.Find(idProduct);

                        if (productsDB != null && productsDB.idCompany == userLoggedIn[0])
                        {
                            db.product.Remove(productsDB);
                            db.SaveChanges();

                            return(MessageService.Custom("Eliminado!"));
                        }
                        else
                        {
                            return(MessageService.WithoutResults());
                        }
                    }
                    else
                    {
                        return(MessageService.AccessDenied());
                    }
                }
            }
            else
            {
                return(MessageService.AccessDenied());
            }
        }