public object UpdateLayawayItemQuantity(IRepository <LayawayItem> layawayItemContext, string Id, int quantity)
        {
            LayawayItem layawayItem = layawayItemContext.Find(Id);

            if (layawayItem != null)
            {
                try
                {
                    layawayItem.ModifiedAt = DateTime.Now;
                    layawayItem.Quantity   = quantity;
                    layawayItemContext.Update(layawayItem);
                    layawayItemContext.Commit();
                    return(new { Successful = true, Message = "Item update succeeded." });
                }
                catch (Exception ex)
                {
                    // log error
                    Console.WriteLine(ex);

                    // send message
                    return(new { Successful = false, Message = "Item update failed." });
                }
            }
            else
            {
                return(new { Successful = false, Message = "Item not found." });
            }
        }
        public void AddToLayaway(HttpContextBase httpContext, string productId)
        {
            Layaway     layaway = GetLayaway(httpContext, true);
            LayawayItem item    = layaway.LayawayItems.FirstOrDefault(p => p.ProductId == productId);

            if (item == null)
            {
                item = new LayawayItem()
                {
                    LayawayId  = layaway.Id,
                    ProductId  = productId,
                    Quantity   = 1,
                    ModifiedAt = DateTime.Now
                };

                layaway.LayawayItems.Add(item);
            }
            else
            {
                ++item.Quantity;
                item.ModifiedAt = DateTime.Now;
            }

            layawayContext.Commit();
        }
        public object RemoveItemFromLayaway(IRepository <LayawayItem> layawayItemContext, string Id)
        {
            LayawayItem itemToDelete = layawayItemContext.Find(Id);

            if (itemToDelete == null)
            {
                return(new { Successful = false, Message = "Item not found.", ItemId = "" });
            }
            else
            {
                layawayItemContext.Delete(Id);
                layawayItemContext.Commit();
                return(new { Successful = true, Message = "Item deleted.", ItemId = Id });
            }
        }
        public void RemoveFromLayaway(HttpContextBase httpContext, string itemId)
        {
            Layaway     layaway = GetLayaway(httpContext, true);
            LayawayItem item    = layaway.LayawayItems.FirstOrDefault(p => p.Id == itemId);

            if (item != null)
            {
                if (item.Quantity > 1)
                {
                    --item.Quantity;
                    layawayContext.Commit();
                }
                else
                {
                    layaway.LayawayItems.Remove(item);
                    layawayContext.Commit();
                }
            }
        }