Example #1
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);
        }
Example #2
0
        public void DeleteOrganizationProduct(int organizationProductID, bool bypass = true)
        {
            if (!UserSession.CurrentUser.IsSystemAdmin && bypass)
            {
                return;
            }
            try
            {
                OrganizationProducts organizationProducts = new OrganizationProducts(UserSession.LoginUser);
                organizationProducts.LoadByOrganizationProductID(organizationProductID);
                UserProducts userProducts = new UserProducts(UserSession.LoginUser);
                //userProducts.LoadByOrganizationProductAndVersionID(organizationProducts[0].OrganizationID, "hola", "adios");
                userProducts.LoadByOrganizationProductAndVersionID(organizationProducts[0].OrganizationID, organizationProducts[0].ProductID, organizationProducts[0].ProductVersionID);
                userProducts.DeleteAll();
                userProducts.Save();
                organizationProducts.DeleteFromDB(organizationProductID);

                Product p           = Products.GetProduct(TSAuthentication.GetLoginUser(), organizationProducts[0].ProductID);
                string  description = String.Format("{0} deleted product association to {1} ", TSAuthentication.GetUser(TSAuthentication.GetLoginUser()).FirstLastName, p.Name);
                ActionLogs.AddActionLog(TSAuthentication.GetLoginUser(), ActionLogType.Delete, ReferenceType.Organizations, organizationProducts[0].OrganizationID, description);
            }
            catch (Exception ex)
            {
                DataUtils.LogException(UserSession.LoginUser, ex);
            }
        }