Ejemplo n.º 1
0
        public static string GetOrganizationProductItem(RestCommand command, int organizationID, int productID, int organizationProductID)
        {
            Organization item = Organizations.GetOrganization(command.LoginUser, organizationID);

            if (item == null || item.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            Product product = Products.GetProduct(command.LoginUser, productID);

            if (product == null || product.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.NotFound);
            }
            OrganizationProduct organizationProduct = OrganizationProducts.GetOrganizationProduct(command.LoginUser, organizationProductID);

            if (organizationProduct == null || organizationProduct.OrganizationID != organizationID)
            {
                throw new RestException(HttpStatusCode.NotFound);
            }

            OrganizationProductsView organizationProductsView = new OrganizationProductsView(command.LoginUser);

            organizationProductsView.LoadByOrganizationProductID(organizationProductID, true);

            return(organizationProductsView.GetXml("OrganizationProducts", "OrganizationProduct", true, command.Filters));
        }
Ejemplo n.º 2
0
        public static string DeleteOrganizationProductItem(RestCommand command, int organizationID, int productID, int organizationProductID)
        {
            Organization item = Organizations.GetOrganization(command.LoginUser, organizationID);

            if (item == null || item.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            Product product = Products.GetProduct(command.LoginUser, productID);

            if (product == null || product.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.NotFound);
            }
            OrganizationProduct organizationProduct = OrganizationProducts.GetOrganizationProduct(command.LoginUser, organizationProductID);

            if (organizationProduct == null || organizationProduct.OrganizationID != organizationID)
            {
                throw new RestException(HttpStatusCode.NotFound);
            }

            string result = OrganizationProductsView.GetOrganizationProductsViewItem(command.LoginUser, organizationProduct.OrganizationProductID).GetXml("OrganizationProduct", true);
            OrganizationProducts organizationProducts = new OrganizationProducts(command.LoginUser);

            organizationProducts.DeleteFromDB(organizationProductID);
            return(result);
        }
Ejemplo n.º 3
0
        public static string GetOrganizationProductItems(RestCommand command, int organizationID, int productID, bool orderByDateCreated = false)
        {
            Organization item = Organizations.GetOrganization(command.LoginUser, organizationID);

            if (item == null || item.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            Product product = Products.GetProduct(command.LoginUser, productID);

            if (product == null || product.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.NotFound);
            }

            OrganizationProductsView organizationProductsView = new OrganizationProductsView(command.LoginUser);

            if (orderByDateCreated)
            {
                organizationProductsView.LoadByOrganizationAndProductIDs(organizationID, productID, "DateCreated DESC");
            }
            else
            {
                organizationProductsView.LoadByOrganizationAndProductIDs(organizationID, productID);
            }

            return(organizationProductsView.GetXml("OrganizationProducts", "OrganizationProduct", true, command.Filters));
        }
Ejemplo n.º 4
0
        public static string UpdateOrganizationProductItem(RestCommand command, int organizationID, int productID, int organizationProductID)
        {
            Organization item = Organizations.GetOrganization(command.LoginUser, organizationID);

            if (item == null || item.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            Product product = Products.GetProduct(command.LoginUser, productID);

            if (product == null || product.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.NotFound);
            }
            OrganizationProduct organizationProduct = OrganizationProducts.GetOrganizationProduct(command.LoginUser, organizationProductID);

            if (organizationProduct == null || organizationProduct.OrganizationID != organizationID)
            {
                throw new RestException(HttpStatusCode.NotFound);
            }

            organizationProduct.ReadFromXml(command.Data, false);
            organizationProduct.Collection.Save();
            organizationProduct.UpdateCustomFieldsFromXml(command.Data);

            return(OrganizationProductsView.GetOrganizationProductsViewItem(command.LoginUser, organizationProduct.OrganizationProductID).GetXml("OrganizationProduct", true));
        }