Ejemplo n.º 1
0
        /// <summary>
        /// Remove item.
        /// </summary>
        /// <param name="item">Item to remove.</param>
        /// <returns>True if the operation was successful.</returns>
        public bool DeleteItem(PICA_B2C.Business.MainModule.Entities.Models.Item item)
        {
            using (AES_Pica_Items context = new AES_Pica_Items())
            {
                var currentItem = (from it in context.Items
                                   where it.ItemId == item.ItemId
                                   select it).FirstOrDefault();

                context.Items.Attach(currentItem);
                context.Entry(currentItem).State = System.Data.Entity.EntityState.Deleted;
                context.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the items of a customer.
        /// </summary>
        /// <param name="customerId">Customer Id.</param>
        /// <returns>List items.</returns>
        public List <PICA_B2C.Business.MainModule.Entities.Models.Item> GetItemsByCustomer(int customerId)
        {
            using (AES_Pica_Items context = new AES_Pica_Items())
            {
                var query = from itm in context.Items where itm.ClienteId == customerId select itm;

                var lstItems = query.Select(itm => new PICA_B2C.Business.MainModule.Entities.Models.Item
                {
                    ItemId   = itm.ItemId,
                    Quantity = itm.Cantidad,
                    //= itm.ClienteId,
                    ProductId = itm.ProductoId
                }).ToList();

                return(lstItems.ToList());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add new item.
        /// </summary>
        /// <param name="item">Item to add.</param>
        /// <param name="customerId">Customer Id.</param>
        /// <returns>True if the operation was successful.</returns>
        public bool AddItem(PICA_B2C.Business.MainModule.Entities.Models.Item item, int customerId)
        {
            Item newItem = new Item
            {
                ItemId     = item.ItemId,
                Cantidad   = item.Quantity,
                ClienteId  = customerId,
                ProductoId = item.ProductId
            };

            using (AES_Pica_Items context = new AES_Pica_Items())
            {
                context.Items.Add(newItem);
                context.SaveChanges();
                return(true);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Modify item.
        /// </summary>
        /// <param name="item">Item to modify</param>
        /// <returns>True if the operation was successful.</returns>
        public bool ModifyQuantityToItem(PICA_B2C.Business.MainModule.Entities.Models.Item item)
        {
            using (AES_Pica_Items context = new AES_Pica_Items())
            {
                Item itemCurrent = (from itm in context.Items
                                    where itm.ItemId == item.ItemId
                                    select itm).FirstOrDefault();

                if (itemCurrent != null)
                {
                    itemCurrent.Cantidad = item.Quantity;

                    context.SaveChanges();
                    return(true);
                }
                else
                {
                    throw new InvalidOperationException("Item inexistente");
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Remove items from a customer.
        /// </summary>
        /// <param name="customerId">Customer Id.</param>
        /// <returns>True if the operation was successful.</returns>
        public bool DeleteItemsByCustomerId(int customerId)
        {
            using (AES_Pica_Items context = new AES_Pica_Items())
            {
                var lstItems = (from it in context.Items
                                where it.ClienteId == customerId
                                select it);

                if ((lstItems != null))
                {
                    foreach (var itm in lstItems)
                    {
                        context.Items.Attach(itm);
                        context.Entry(itm).State = System.Data.Entity.EntityState.Deleted;
                    }

                    context.SaveChanges();
                }

                return(true);
            }
        }