Esempio n. 1
0
        public static ShoppingCartItemModel FromBusinessEntity(Business.Entities.ShoppingCartItem businessEntity)
        {
            ShoppingCartItemModel model = new ShoppingCartItemModel();

            model.Id       = businessEntity.ID;
            model.ItemID   = businessEntity.ItemID;
            model.Quantity = businessEntity.Quantity;
            model.StoreID  = businessEntity.StoreID;
            model.StatusID = businessEntity.StatusID;

            if (businessEntity.Definition != null)
            {
                model.Definition = ShoppingCartItemDefinitionModel.FromBusinessEntity(businessEntity.Definition);
            }

            if (businessEntity.State != null)
            {
                model.State = ShoppingCartItemStateModel.FromBusinessEntity(businessEntity.State);
            }

            if (businessEntity.Store != null)
            {
                model.Store = StoreModel.FromBusinessEntity(businessEntity.Store);
            }

            return(model);
        }
Esempio n. 2
0
        public ActionResult Update(FormCollection action, string save, string finalize)
        {
            string cartId = action["Id"].ToString();

            try
            {
                Business.Entities.ShoppingCart cart = new Business.Entities.ShoppingCart();

                long actionId = save == "SAVE" ? 4 : 1;

                string[] iDs      = action["hfID"].Split(',');
                string[] quantity = action["txtQuantity"].Split(',');
                string[] storeId  = action["ddlStores"].Split(',');

                for (int i = 0; i < iDs.Length; i++)
                {
                    Business.Entities.ShoppingCartItem item = new Business.Entities.ShoppingCartItem();
                    item.ID       = long.Parse(iDs[i]);
                    item.Quantity = long.Parse(quantity[i]);
                    item.StoreID  = long.Parse(storeId[i]);

                    cart.Items.Add(item);
                }

                cart.ID = long.Parse(cartId);

                shoppingCartManager.Update(cart, actionId);

                return(RedirectToAction("Select", new { id = cartId }));
            }
            catch (Exception ex)
            {
                Danger(ex.Message);
                return(RedirectToAction("Select", new { id = cartId }));
            }
        }
Esempio n. 3
0
        public override Collection <Business.Entities.ShoppingCart> ToBusinessEntity()
        {
            DataTable shoppingCartTable = this.DataEntity.Tables[0];
            Collection <Business.Entities.ShoppingCart> shoppingCarts = null;

            if (this.DataEntity.Tables.Count > 0)
            {
                shoppingCarts = new Collection <Business.Entities.ShoppingCart>();

                foreach (DataRow row in shoppingCartTable.Rows)
                {
                    Business.Entities.ShoppingCart shoppingCart = new Business.Entities.ShoppingCart();
                    shoppingCart.ID       = row.Field <long>("ID");
                    shoppingCart.StatusID = row.Field <long>("StatusID");
                    shoppingCart.OwnerID  = row.Field <long>("OwnerID");

                    shoppingCart.State             = new Business.Entities.ShoppingCartState();
                    shoppingCart.State.ID          = shoppingCart.StatusID;
                    shoppingCart.State.Code        = row.Field <string>("StateCode");
                    shoppingCart.State.Description = row.Field <string>("StateDescription");

                    shoppingCart.Owner          = new Business.Entities.User();
                    shoppingCart.Owner.ID       = row.Field <long>("OwnerID");
                    shoppingCart.Owner.Username = row.Field <string>("OwnerUsername");
                    shoppingCart.Owner.Name     = row.Field <string>("OwnerName");

                    shoppingCarts.Add(shoppingCart);
                }

                if (this.DataEntity.Tables.Count > 1)
                {
                    DataTable shoppingCartItemsTable = this.DataEntity.Tables[1];

                    foreach (DataRow row in shoppingCartItemsTable.Rows)
                    {
                        Business.Entities.ShoppingCartItem item = new Business.Entities.ShoppingCartItem();
                        item.ID       = row.Field <long>("ID");
                        item.CartID   = row.Field <long>("CartID");
                        item.ItemID   = row.Field <long>("ItemID");
                        item.Quantity = row.Field <long>("Quantity");
                        item.StoreID  = row.Field <long>("StoreID");
                        item.StatusID = row.Field <long>("StatusID");

                        item.Store             = new Business.Entities.Store();
                        item.Store.ID          = row.Field <long>("StoreID");
                        item.Store.Code        = row.Field <string>("StoreCode");
                        item.Store.Description = row.Field <string>("StoreDescription");

                        item.Definition = new Business.Entities.ShoppingCartItemDefinition();
                        item.Definition.DefaultStoreID  = row.Field <long>("DefaultStoreID");
                        item.Definition.CategoryID      = row.Field <long>("CategoryID");
                        item.Definition.Code            = row.Field <string>("DefinitionCode");
                        item.Definition.DefaultQuantity = row.Field <long>("DefaultQuantity");
                        item.Definition.Description     = row.Field <string>("DefinitionDescription");
                        item.Definition.ID         = row.Field <long>("ItemID");
                        item.Definition.LocationID = row.Field <long>("LocationID");
                        item.Definition.UnitID     = row.Field <long>("UnitTypeID");
                        item.Definition.UnitPrice  = row.Field <decimal>("UnitPrice");

                        item.Definition.Category             = new Business.Entities.Category();
                        item.Definition.Category.ID          = row.Field <long>("CategoryID");
                        item.Definition.Category.Code        = row.Field <string>("DefinitionCode");
                        item.Definition.Category.Description = row.Field <string>("DefinitionDescription");

                        item.Definition.Location             = new Business.Entities.Location();
                        item.Definition.Location.ID          = row.Field <long>("LocationID");
                        item.Definition.Location.Code        = row.Field <string>("LocationCode");
                        item.Definition.Location.Description = row.Field <string>("LocationDescription");
                        item.Definition.Location.Order       = row.Field <long>("LocationOrder");

                        item.Definition.DefaultStore             = new Business.Entities.Store();
                        item.Definition.DefaultStore.ID          = row.Field <long>("DefaultStoreID");
                        item.Definition.DefaultStore.Code        = row.Field <string>("DefaultStoreCode");
                        item.Definition.DefaultStore.Description = row.Field <string>("DefaultStoreDescription");

                        item.Definition.Unit             = new Business.Entities.UnitType();
                        item.Definition.Unit.ID          = row.Field <long>("UnitTypeID");
                        item.Definition.Unit.Code        = row.Field <string>("UnitCode");
                        item.Definition.Unit.Description = row.Field <string>("UnitDescription");

                        item.State             = new Business.Entities.ShoppingCartItemState();
                        item.State.ID          = row.Field <long>("StatusID");
                        item.State.Code        = row.Field <string>("StatusCode");
                        item.State.Description = row.Field <string>("StatusDescription");

                        shoppingCarts.First(s => s.ID == item.CartID).Items.Add(item);
                    }
                }
            }

            return(shoppingCarts);
        }