コード例 #1
0
        public static bool UnAssignAllProducts(ProductFilter filter, int groupId)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    ProductGroup pg = ProductGroupDataSource.Load(p.Id, groupId);
                    if (pg != null)
                    {
                        p.ProductGroups.Remove(pg);
                        p.Save();
                        pg.Delete();
                    }
                }
                currentIndex += 100;
            }

            database.CommitTransaction();
            return(true);
        }
コード例 #2
0
        public static bool AssignAllProducts(ProductFilter filter, int[] groupIds, string groupRestrictions)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            List <Group> groups = new List <Group>();

            foreach (int gid in groupIds)
            {
                Group group = GroupDataSource.Load(gid);
                if (group != null)
                {
                    groups.Add(group);
                }
            }
            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    foreach (Group group in groups)
                    {
                        ProductGroup pg = ProductGroupDataSource.Load(p.Id, group.Id);
                        if (pg == null)
                        {
                            pg = new ProductGroup(p, group);
                            p.ProductGroups.Add(pg);
                        }
                    }

                    switch (groupRestrictions)
                    {
                    case "YES":
                        p.EnableGroups = true;
                        break;

                    case "NO":
                        p.EnableGroups = false;
                        break;

                    default:
                        break;
                    }

                    p.Save();
                }
                currentIndex += 100;
            }

            database.CommitTransaction();
            return(true);
        }
コード例 #3
0
 public static bool DeleteCoupons(int[] couponIds)
 {
     List<string> ids = new List<string>();
     IDatabaseSessionManager database = AbleContext.Current.Database;
     database.BeginTransaction();
     foreach (int cid in couponIds)
     {
         CouponDataSource.Delete(cid);
     }
     database.CommitTransaction();
     return true;
 }
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            List <int> offList = new List <int>();
            List <int> onList  = new List <int>();
            //LOOP THROUGH SIGNUP LIST
            int index = 0;

            foreach (DataListItem item in dlEmailLists.Items)
            {
                int      tempListId = (int)dlEmailLists.DataKeys[index];
                CheckBox selected   = (CheckBox)item.FindControl("Selected");
                if ((selected != null) && (selected.Checked))
                {
                    onList.Add(tempListId);
                }
                else
                {
                    offList.Add(tempListId);
                }
                index++;
            }
            string email = AbleContext.Current.User.Email;

            //PROCESS LISTS THAT SHOULD NOT BE SUBSCRIBED
            foreach (int emailListId in offList)
            {
                EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                if (elu != null)
                {
                    elu.Delete();
                }
            }
            //PROCESS LISTS THAT SHOULD BE SUBSCRIBED
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (int emailListId in onList)
            {
                EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                if (elu == null)
                {
                    EmailList list = EmailListDataSource.Load(emailListId);
                    if (list != null)
                    {
                        list.ProcessSignupRequest(email);
                    }
                }
            }
            //DISPLAY CONFIRMATION
            UpdatedMessage.Visible = true;
            database.CommitTransaction();
        }
コード例 #5
0
        public static bool DeleteAllCountries(string alphabet)
        {
            IList <Country>         countries = CountryDataSource.SearchByName(alphabet + "%");
            IDatabaseSessionManager database  = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (Country country in countries)
            {
                CountryDataSource.Delete(country);
            }
            database.CommitTransaction();
            return(true);
        }
コード例 #6
0
        public static bool DeleteProvinces(int[] provinceIds)
        {
            List <string>           ids      = new List <string>();
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (int cid in provinceIds)
            {
                ProvinceDataSource.Delete(cid);
            }
            database.CommitTransaction();
            return(true);
        }
コード例 #7
0
 public static bool DeleteAllCoupons(SearchFilter filter)
 {
     IList<Coupon> coupons = CouponDataSource.Search(filter.CouponCode, filter.UsageFilter);
     if (coupons != null)
     {
         IDatabaseSessionManager database = AbleContext.Current.Database;
         database.BeginTransaction();
         coupons.DeleteAll();
         database.CommitTransaction();
         return true;
     }
     else return false;
 }
コード例 #8
0
        private void UpdateEmailLists()
        {
            // DETERMINE SELECTED LISTS
            List <int> offList = new List <int>();
            List <int> onList  = new List <int>();
            int        index   = 0;

            foreach (DataListItem item in dlEmailLists.Items)
            {
                int      tempListId = (int)dlEmailLists.DataKeys[index];
                CheckBox selected   = (CheckBox)item.FindControl("Selected");
                if ((selected != null) && (selected.Checked))
                {
                    onList.Add(tempListId);
                }
                else
                {
                    offList.Add(tempListId);
                }
                index++;
            }
            string email = AbleContext.Current.User.Email;

            // PROCESS LISTS THAT SHOULD NOT BE SUBSCRIBED
            foreach (int emailListId in offList)
            {
                EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                if (elu != null)
                {
                    elu.Delete();
                }
            }

            // PROCESS LISTS THAT SHOULD BE SUBSCRIBED
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (int emailListId in onList)
            {
                EmailListUser elu = EmailListUserDataSource.Load(emailListId, email);
                if (elu == null)
                {
                    EmailList list = EmailListDataSource.Load(emailListId);
                    if (list != null)
                    {
                        list.ProcessSignupRequest(email);
                    }
                }
            }
            database.CommitTransaction();
        }
コード例 #9
0
        public static bool AssignProducts(int[] productIds, int[] groupIds, string groupRestrictions)
        {
            List <string>           ids      = new List <string>();
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            List <Group> groups = new List <Group>();

            foreach (int gid in groupIds)
            {
                Group group = GroupDataSource.Load(gid);
                if (group != null)
                {
                    groups.Add(group);
                }
            }

            foreach (int pid in productIds)
            {
                Product product = ProductDataSource.Load(pid);
                foreach (Group group in groups)
                {
                    ProductGroup pg = ProductGroupDataSource.Load(pid, group.Id);
                    if (pg == null)
                    {
                        pg = new ProductGroup(product, group);
                        product.ProductGroups.Add(pg);
                    }
                }

                switch (groupRestrictions)
                {
                case "YES":
                    product.EnableGroups = true;
                    break;

                case "NO":
                    product.EnableGroups = false;
                    break;

                default:
                    break;
                }

                product.Save();
            }
            database.CommitTransaction();
            return(true);
        }
コード例 #10
0
        protected void GoButton_Click(Object sender, EventArgs e)
        {
            String selectedOption = BulkOptions.SelectedValue;

            if (!String.IsNullOrEmpty(selectedOption))
            {
                List <DataKey> selectedItems = GetSelectedItems();
                if (selectedItems.Count > 0)
                {
                    switch (selectedOption)
                    {
                    case "Move":
                        Response.Redirect("MoveCatalogObjects.aspx?CategoryId=" + CurrentCategory.Id + "&Objects=" + FormatSelectedItems(selectedItems));
                        break;

                    case "Delete":
                        IDatabaseSessionManager database = AbleContext.Current.Database;
                        database.BeginTransaction();
                        foreach (DataKey item in selectedItems)
                        {
                            DoDelete((CatalogNodeType)item.Values[1], (int)item.Values[0]);
                        }
                        database.CommitTransaction();
                        break;

                    case "ChangeVisibility":
                        Response.Redirect("ChangeVisibility.aspx?CategoryId=" + CurrentCategory.Id + "&Objects=" + FormatSelectedItems(selectedItems));
                        break;
                    }
                }
            }

            BulkOptions.SelectedIndex = 0;

            // DETERMINE IF THE CURRENT PAGE INDEX IS TOO FAR
            if (CGrid.PageIndex > 0)
            {
                decimal pageSize      = (decimal)CGrid.PageSize;
                decimal totalObjects  = (decimal)CatalogNodeDataSource.CountForCategory(CurrentCategory.Id);
                int     lastPageIndex = (int)Math.Ceiling(totalObjects / pageSize) - 1;
                if (CGrid.PageIndex > lastPageIndex)
                {
                    // ALL ITEMS ON CURRENT PAGE > 1 WERE DELETED
                    // SET TO LAST CALCULATED PAGE INDEX
                    CGrid.PageIndex = lastPageIndex;
                }
            }
        }
コード例 #11
0
        public static bool DeleteAllProvinces(string countryCode)
        {
            Country country = CountryDataSource.Load(countryCode);

            if (country != null)
            {
                IDatabaseSessionManager database = AbleContext.Current.Database;
                database.BeginTransaction();
                country.Provinces.DeleteAll();
                database.CommitTransaction();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #12
0
        private void UpdateChildNodes(int categoryId, CatalogVisibility visibility)
        {
            IList <CatalogNode>     children = CatalogDataSource.LoadForCategory(categoryId, false);
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (CatalogNode child in children)
            {
                child.Visibility             = visibility;
                child.ChildObject.Visibility = visibility;
                child.Save(true);
                if (child.CatalogNodeType == CatalogNodeType.Category)
                {
                    UpdateChildNodes(child.CatalogNodeId, visibility);
                }
            }
            database.CommitTransaction();
        }
コード例 #13
0
        public static bool UnAssignProducts(int[] productIds, int groupId)
        {
            List <string>           ids      = new List <string>();
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (int pid in productIds)
            {
                ProductGroup pg = ProductGroupDataSource.Load(pid, groupId);
                if (pg != null)
                {
                    var product = pg.Product;
                    product.ProductGroups.Remove(pg);
                    product.Save();
                    pg.Delete();
                }
            }
            database.CommitTransaction();
            return(true);
        }
コード例 #14
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            int _NewCategoryId = AlwaysConvert.ToInt(NewPath.SelectedValue);

            if (_CategoryId != _NewCategoryId)
            {
                Category currentCategory = CategoryDataSource.Load(_CategoryId);
                Category targetCategory  = CategoryDataSource.Load(_NewCategoryId);
                // CATEGORIES CAN ONLY BE MOVED, NOT MULTIPARENTED
                if (_Categories != null)
                {
                    foreach (Category category in _Categories)
                    {
                        category.ParentId = _NewCategoryId;
                        category.Save();
                    }
                }
                bool moveAll    = (MoveOptions.SelectedValue == "MoveAll");
                bool moveSingle = (MoveOptions.SelectedValue == "MoveSingle");
                // LOOP SELECTED ITEMS AND MOVE AS NEEDED
                IDatabaseSessionManager database = AbleContext.Current.Database;
                database.BeginTransaction();
                foreach (ICatalogable catalogItem in _CatalogItems)
                {
                    if (catalogItem is Product)
                    {
                        Product product = (Product)catalogItem;
                        if (moveAll)
                        {
                            product.Categories.Clear();
                        }
                        else if (moveSingle)
                        {
                            product.Categories.Remove(_CategoryId);
                        }
                        if (!product.Categories.Contains(_NewCategoryId))
                        {
                            product.Categories.Add(_NewCategoryId);
                        }
                        product.Categories.Save();
                    }
                    else if (catalogItem is Webpage)
                    {
                        Webpage webpage = (Webpage)catalogItem;
                        if (moveAll)
                        {
                            webpage.Categories.Clear();
                        }
                        else if (moveSingle)
                        {
                            webpage.Categories.Remove(_CategoryId);
                        }
                        if (!webpage.Categories.Contains(_NewCategoryId))
                        {
                            webpage.Categories.Add(_NewCategoryId);
                        }
                        webpage.Categories.Save();
                    }
                    else if (catalogItem is Link)
                    {
                        Link link = (Link)catalogItem;
                        if (moveAll)
                        {
                            link.Categories.Clear();
                        }
                        else if (moveSingle)
                        {
                            link.Categories.Remove(_CategoryId);
                        }
                        if (!link.Categories.Contains(_NewCategoryId))
                        {
                            link.Categories.Add(_NewCategoryId);
                        }
                        link.Categories.Save();
                    }
                }
                database.CommitTransaction();
            }
            Response.Redirect("Browse.aspx?CategoryId=" + _NewCategoryId.ToString());
        }
コード例 #15
0
        protected void BatchButton_Click(object sender, EventArgs e)
        {
            List <string> messages = new List <string>();
            List <int>    orderIds = GetSelectedOrderIds();

            if (orderIds.Count > 0)
            {
                if (BatchAction.SelectedValue.StartsWith("OS_"))
                {
                    //UPDATE ORDER STATUS REQUESTED
                    int orderStatusId = AlwaysConvert.ToInt(BatchAction.SelectedValue.Substring(3));
                    //VALIDATE STATUS
                    OrderStatus status = OrderStatusDataSource.Load(orderStatusId);
                    if (status != null)
                    {
                        IDatabaseSessionManager database = AbleContext.Current.Database;
                        database.BeginTransaction();
                        foreach (int orderId in orderIds)
                        {
                            Order order = OrderDataSource.Load(orderId);
                            if (order != null)
                            {
                                order.UpdateOrderStatus(status);
                            }
                        }
                        database.CommitTransaction();
                    }
                }
                else
                {
                    switch (BatchAction.SelectedValue)
                    {
                    case "INVOICE":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Print/Invoices.aspx");
                        break;

                    case "PACKSLIP":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Print/PackSlips.aspx");
                        break;

                    case "PULLSHEET":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Print/PullSheet.aspx");
                        break;

                    case "CANCEL":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Batch/Cancel.aspx");
                        break;

                    case "SHIPOPT":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("Batch/Ship.aspx");
                        break;

                    case "SHIP":
                        AbleContext.Current.Database.BeginTransaction();
                        int shipCount = 0;
                        foreach (int orderId in orderIds)
                        {
                            Order order = OrderDataSource.Load(orderId);
                            if (order != null && order.Shipments != null)
                            {
                                bool shipped       = false;
                                int  shipmentCount = order.Shipments.Count;
                                for (int i = 0; i < shipmentCount; i++)
                                {
                                    OrderShipment shipment = order.Shipments[i];
                                    if (shipment != null && !shipment.IsShipped)
                                    {
                                        shipment.Ship();
                                        shipped = true;
                                    }
                                }
                                if (shipped)
                                {
                                    messages.Add("Order #" + order.OrderNumber + " shipped.");
                                    shipCount++;
                                }
                                else
                                {
                                    messages.Add("Order #" + order.OrderNumber + " did not have any unshipped items.");
                                }
                            }
                        }
                        AbleContext.Current.Database.CommitTransaction();
                        messages.Add(shipCount + " orders shipped.");
                        break;

                    case "PAY":
                        AbleContext.Current.Database.BeginTransaction();
                        int payCount = 0;
                        foreach (int orderId in orderIds)
                        {
                            Order order = OrderDataSource.Load(orderId);
                            if (order != null)
                            {
                                bool paid         = false;
                                int  paymentCount = order.Payments.Count;
                                for (int i = 0; i < paymentCount; i++)
                                {
                                    Payment payment = order.Payments[i];
                                    if (payment.PaymentStatus == PaymentStatus.Authorized)
                                    {
                                        payment.Capture(payment.Amount, true);
                                        paid = true;
                                    }
                                    else if (payment.PaymentStatus == PaymentStatus.Unprocessed)
                                    {
                                        payment.Authorize();
                                        paid = true;
                                    }
                                }
                                if (paid)
                                {
                                    payCount++;
                                    messages.Add("Order " + order.OrderNumber.ToString() + " processed.");
                                }
                                else
                                {
                                    messages.Add("Order " + order.OrderNumber.ToString() + " does not have any payments to be processed.");
                                }
                            }
                        }
                        AbleContext.Current.Database.CommitTransaction();
                        messages.Add(payCount + " orders processed.");
                        break;

                    case "DELETE":
                        if (AbleContext.Current.User.IsSystemAdmin)
                        {
                            IDatabaseSessionManager database = AbleContext.Current.Database;
                            database.BeginTransaction();
                            foreach (int orderId in orderIds)
                            {
                                OrderDataSource.Delete(orderId);
                            }
                            database.CommitTransaction();
                            OrderGrid.DataBind();
                        }
                        break;

                    case "EXPORT":
                        AbleContext.Current.Session.SelectedOrderIds = orderIds;
                        Response.Redirect("../DataExchange/OrdersExport.aspx?type=selected");
                        break;
                    }
                }
            }
            if (messages.Count > 0)
            {
                BatchMessage.Visible = true;
                BatchMessage.Text    = string.Join("<br />", messages.ToArray());
            }
            BatchAction.SelectedIndex = -1;
            OrderGrid.DataBind();
        }