예제 #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));
        }
예제 #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);
        }
예제 #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));
        }
예제 #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));
        }