Esempio n. 1
0
        public void SaveItems(IEnumerable <ShoppingCartItem> items)
        {
            //run this in a transaction
            var cmds = new List <DbCommand>();

            foreach (var item in this.OrderItems)
            {
                cmds.Add(item.GetDeleteCommand());
            }

            //now add in these items
            foreach (var item in items)
            {
                var newItem = new OrderItem();
                newItem.SKU            = item.Product.SKU;
                newItem.OrderID        = this.OrderID;
                newItem.Quantity       = item.Quantity;
                newItem.DateAdded      = item.DateAdded;
                newItem.Discount       = item.Discount;
                newItem.DiscountReason = item.DiscountReason;
                cmds.Add(newItem.GetInsertCommand());
            }

            var db = new KonaDB();

            db.ExecuteTransaction(cmds);
        }
Esempio n. 2
0
        public static Order FindCheckedOutOrder(Guid orderID)
        {
            //load the order
            var order = Order.SingleOrDefault(x => x.OrderID == orderID);

            //if it's not null, pull the products
            if (order != null)
            {
                KonaDB db  = new KonaDB();
                var    qry = (from p in db.Products
                              join oi in db.OrderItems on p.SKU equals oi.SKU
                              where oi.OrderID == orderID
                              select p).ToList();

                foreach (var item in order.OrderItems)
                {
                    item.Item = qry.SingleOrDefault(x => x.SKU == item.SKU);
                }

                //get the addresses
                order.ShippingAddress = Address.SingleOrDefault(x => x.AddressID == order.ShippingAddressID);
                order.BillingAddress  = Address.SingleOrDefault(x => x.AddressID == order.BillingAddressID);
            }


            return(order);
        }
Esempio n. 3
0
        public ActionResult Create(FormCollection form)
        {

            Widget newWidget = new Widget();
            UpdateModel<Widget>(newWidget);

            //the category ID should be sent in as "categoryid"
            string categoryID = form["CategoryID"];
 
            var widgetCommand = newWidget.GetInsertCommand();

            //save the category too
            Categories_Widget map = new Categories_Widget();
            int catid = 0;
            int.TryParse(categoryID, out catid);
            map.CategoryID = catid;
            map.WidgetID = newWidget.WidgetID;

            var mapCommand = map.GetInsertCommand();

            KonaDB db = new KonaDB();
            db.ExecuteTransaction(new List<DbCommand>() { widgetCommand, mapCommand });

            //return a json result with the ID
            return Json(new { ID = newWidget.WidgetID, Zone = newWidget.Zone });

        }
Esempio n. 4
0
        public static Order FindCheckedOutOrder(Guid orderID) {

            //load the order
            var order = Order.SingleOrDefault(x => x.OrderID == orderID);

            //if it's not null, pull the products
            if (order != null) {
                KonaDB db = new KonaDB();
                var qry = (from p in db.Products
                          join oi in db.OrderItems on p.SKU equals oi.SKU
                          where oi.OrderID == orderID
                          select p).ToList();

                foreach (var item in order.OrderItems) {
                    item.Item = qry.SingleOrDefault(x => x.SKU == item.SKU);
                }

                //get the addresses
                order.ShippingAddress = Address.SingleOrDefault(x => x.AddressID == order.ShippingAddressID);
                order.BillingAddress = Address.SingleOrDefault(x => x.AddressID == order.BillingAddressID);

            }

  
            return order;
        }
Esempio n. 5
0
        public ActionResult Create(FormCollection form)
        {
            Widget newWidget = new Widget();

            UpdateModel <Widget>(newWidget);

            //the category ID should be sent in as "categoryid"
            string categoryID = form["CategoryID"];

            var widgetCommand = newWidget.GetInsertCommand();

            //save the category too
            Categories_Widget map = new Categories_Widget();
            int catid             = 0;

            int.TryParse(categoryID, out catid);
            map.CategoryID = catid;
            map.WidgetID   = newWidget.WidgetID;

            var mapCommand = map.GetInsertCommand();

            KonaDB db = new KonaDB();

            db.ExecuteTransaction(new List <DbCommand>()
            {
                widgetCommand, mapCommand
            });

            //return a json result with the ID
            return(Json(new { ID = newWidget.WidgetID, Zone = newWidget.Zone }));
        }
Esempio n. 6
0
        public static List <Category> GetHierarchicalCategories()
        {
            var db = new KonaDB();

            var allCategories = db.Select.From <Category>().InnerJoin <CategoryLocalized>().Where("LanguageCode")
                                .IsEqualTo(System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName)
                                .ExecuteTypedList <Category>();

            //var allCategories = from c in db.Categories
            //           join cl in db.CategoryLocalizeds on c.CategoryID equals cl.CategoryID
            //           where cl.LanguageCode == System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName
            //           select new Category {
            //               ParentID = c.ParentID,
            //               CategoryID = c.CategoryID,
            //               LocalizedName = cl.Name,
            //               Slug = cl.Slug,

            //           };
            List <Category> result = allCategories.Where(x => x.ParentID == null).ToList();

            result.ForEach(x => x.SubCategories =
                               allCategories.Where(y => y.ParentID == x.CategoryID).ToList());

            return(result);
        }
Esempio n. 7
0
        public static Category GetCategoryPage(string slug)
        {
            //pull the category
            CategoryLocalized localized = null;

            if (!string.IsNullOrEmpty(slug))
            {
                localized = CategoryLocalized.SingleOrDefault(x => x.Slug.ToLower() == slug.ToLower() && x.LanguageCode == System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
            }

            //default is to pull the home page
            if (localized == null)
            {
                //it's a home page - pull em
                localized = CategoryLocalized.SingleOrDefault(x => x.IsHome && x.LanguageCode == System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
            }

            //shouldn't be null - if it is then we have an issue
            if (localized == null)
            {
                throw new Exception("There is no home category defined for the site - better set 'em");
            }

            Category result = Category.SingleOrDefault(x => x.CategoryID == localized.CategoryID);

            result.Name = localized.Name;
            result.Slug = localized.Slug;
            //set the products
            KonaDB db = new KonaDB();

            result.Products = (from p in db.Products
                               join ci in db.Categories_Products on p.SKU equals ci.SKU
                               select p).Distinct().ToList() ?? new List <Product>();

            //pull the widgets
            result.Widgets = (from w in db.Widgets
                              join cw in db.Categories_Widgets on w.WidgetID equals cw.WidgetID
                              select w).ToList() ?? new List <Widget>();


            //set the products for the Widget
            foreach (var widget in result.Widgets)
            {
                widget.Products = new List <Product>();
                foreach (string sku in widget.GetSkuArray())
                {
                    var widgetProduct = result.Products.SingleOrDefault(x => x.SKU.Equals(sku, StringComparison.InvariantCultureIgnoreCase));
                    if (widgetProduct != null)
                    {
                        widget.Products.Add(widgetProduct);
                    }
                }
            }


            return(result);
        }
Esempio n. 8
0
        public void LoadProducts() {

            //use some SubSonic love here
            if (!String.IsNullOrEmpty(this.SKUList)) {
                KonaDB db = new KonaDB();
                string[] skus=this.GetSkuArray();
                var products = db.Select.From<Product>().Where("sku").In(skus).ExecuteTypedList<Product>();
            
                //order it - since IN isn't a very good ordering thinger
                this.Products = new List<Product>();
                foreach (string s in skus) {
                    this.Products.Add(products.Single(x => x.SKU == s));
                }
            }

        }
Esempio n. 9
0
        public static Category GetCategoryPage(string slug){

            //pull the category
            CategoryLocalized localized=null;
            if(!string.IsNullOrEmpty(slug))
                localized=CategoryLocalized.SingleOrDefault(x=>x.Slug.ToLower()==slug.ToLower() && x.LanguageCode==System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
            
            //default is to pull the home page
            if(localized==null){
                //it's a home page - pull em
                localized=CategoryLocalized.SingleOrDefault(x=>x.IsHome && x.LanguageCode==System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
            }

            //shouldn't be null - if it is then we have an issue
            if (localized == null)
                throw new Exception("There is no home category defined for the site - better set 'em");

            Category result = Category.SingleOrDefault(x => x.CategoryID == localized.CategoryID);

            result.Name = localized.Name;
            result.Slug = localized.Slug;
            //set the products
            KonaDB db = new KonaDB();
            result.Products = (from p in db.Products
                               join ci in db.Categories_Products on p.SKU equals ci.SKU
                               select p).Distinct().ToList() ?? new List<Product>();
            
            //pull the widgets
            result.Widgets = (from w in db.Widgets
                              join cw in db.Categories_Widgets on w.WidgetID equals cw.WidgetID
                              select w).ToList() ?? new List<Widget>();


            //set the products for the Widget
            foreach (var widget in result.Widgets) {
                widget.Products = new List<Product>();
                foreach (string sku in widget.GetSkuArray()) {
                    var widgetProduct = result.Products.SingleOrDefault(x => x.SKU.Equals(sku, StringComparison.InvariantCultureIgnoreCase));
                    if (widgetProduct != null)
                        widget.Products.Add(widgetProduct);
                }
            }


            return result;
        }
Esempio n. 10
0
 public ActionResult SortPages()
 {
     if (Request.Form["pageid"] != null)
     {
         //pull out all pageid's
         var    pages     = Request.Form.GetValues("pageid").Where(x => !String.IsNullOrEmpty(x)).ToArray();
         int    listOrder = 0;
         KonaDB db        = new KonaDB();
         foreach (var pg in pages)
         {
             //subsonic style :)
             db.Update <Page>().Set(x => x.ListOrder == listOrder).Execute();
             listOrder++;
         }
     }
     return(new EmptyResult());
 }
Esempio n. 11
0
        public void LoadProducts()
        {
            //use some SubSonic love here
            if (!String.IsNullOrEmpty(this.SKUList))
            {
                KonaDB   db       = new KonaDB();
                string[] skus     = this.GetSkuArray();
                var      products = db.Select.From <Product>().Where("sku").In(skus).ExecuteTypedList <Product>();

                //order it - since IN isn't a very good ordering thinger
                this.Products = new List <Product>();
                foreach (string s in skus)
                {
                    this.Products.Add(products.Single(x => x.SKU == s));
                }
            }
        }
Esempio n. 12
0
 public ActionResult OrderWidgets()
 {
     if (Request.Form["widgetid"] != null)
     {
         //pull out all widgetid's
         var    ids       = Request.Form.GetValues("widgetid").Where(x => !String.IsNullOrEmpty(x)).ToArray();
         int    listOrder = 0;
         KonaDB db        = new KonaDB();
         foreach (var id in ids)
         {
             var widgetID = new Guid(id);
             //subsonic style...
             db.Update <Widget>().Set(x => x.ListOrder == listOrder);
             listOrder++;
         }
     }
     return(new EmptyResult());
 }
Esempio n. 13
0
        public static Order FindCurrentOrCreateNew(string userName){
            
            var db = new KonaDB();

            Order result = Order.SingleOrDefault(x => x.UserName == userName && x.OrderStatusID == (int)OrderStatus.NotCheckedOut);

            if (result == null) {
                result = new Order();
                result.OrderID = Guid.NewGuid();
                result.UserName = userName;
                result.UserLanguageCode = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
                result.OrderStatusID = (int)OrderStatus.NotCheckedOut;
                result.Add("");
            } else {
                result.ShippingAddress = Address.SingleOrDefault(x => x.AddressID == result.ShippingAddressID);
                result.BillingAddress = Address.SingleOrDefault(x => x.AddressID == result.BillingAddressID);
            }
            return result;
        }
Esempio n. 14
0
        public void SaveWidgetOrder()
        {
            var    commands = new List <DbCommand>();
            KonaDB db       = new KonaDB();

            if (Request.Form["widgetid"] != null)
            {
                //pull out all widgetid's
                var ids       = Request.Form.GetValues("widgetid").Where(x => !String.IsNullOrEmpty(x)).ToArray();
                int listOrder = 0;
                foreach (var id in ids)
                {
                    var widgetID = new Guid(id);
                    //subsonic style...
                    commands.Add(db.Update <Widget>().Set(x => x.ListOrder == listOrder).Where(x => x.WidgetID == widgetID).GetCommand().ToDbCommand());
                    listOrder++;
                }
            }
            //transaction :)
            db.ExecuteTransaction(commands);
        }
Esempio n. 15
0
        public static Order FindCurrentOrCreateNew(string userName)
        {
            var db = new KonaDB();

            Order result = Order.SingleOrDefault(x => x.UserName == userName && x.OrderStatusID == (int)OrderStatus.NotCheckedOut);

            if (result == null)
            {
                result                  = new Order();
                result.OrderID          = Guid.NewGuid();
                result.UserName         = userName;
                result.UserLanguageCode = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
                result.OrderStatusID    = (int)OrderStatus.NotCheckedOut;
                result.Add("");
            }
            else
            {
                result.ShippingAddress = Address.SingleOrDefault(x => x.AddressID == result.ShippingAddressID);
                result.BillingAddress  = Address.SingleOrDefault(x => x.AddressID == result.BillingAddressID);
            }
            return(result);
        }
Esempio n. 16
0
        public static List<Category> GetHierarchicalCategories() {
            var db=new KonaDB();

            var allCategories = db.Select.From<Category>().InnerJoin<CategoryLocalized>().Where("LanguageCode")
                .IsEqualTo(System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName)
                .ExecuteTypedList<Category>();

            //var allCategories = from c in db.Categories
            //           join cl in db.CategoryLocalizeds on c.CategoryID equals cl.CategoryID
            //           where cl.LanguageCode == System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName
            //           select new Category {
            //               ParentID = c.ParentID,
            //               CategoryID = c.CategoryID,
            //               LocalizedName = cl.Name,
            //               Slug = cl.Slug,

            //           };
            List<Category> result = allCategories.Where(x => x.ParentID == null).ToList();

            result.ForEach(x => x.SubCategories = 
                allCategories.Where(y => y.ParentID == x.CategoryID).ToList());

            return result;
        }
Esempio n. 17
0
        public void SaveItems(IEnumerable<ShoppingCartItem> items) {

            //run this in a transaction
            var cmds = new List<DbCommand>();
            foreach (var item in this.OrderItems) {
                cmds.Add(item.GetDeleteCommand());
            }

            //now add in these items
            foreach (var item in items) {
                var newItem = new OrderItem();
                newItem.SKU = item.Product.SKU;
                newItem.OrderID = this.OrderID;
                newItem.Quantity = item.Quantity;
                newItem.DateAdded = item.DateAdded;
                newItem.Discount = item.Discount;
                newItem.DiscountReason = item.DiscountReason;
                cmds.Add(newItem.GetInsertCommand());
            }

            var db = new KonaDB();
            db.ExecuteTransaction(cmds);

        }
Esempio n. 18
0
 public ActionResult SortPages() {
     if (Request.Form["pageid"] != null) {
         //pull out all pageid's
         var pages = Request.Form.GetValues("pageid").Where(x => !String.IsNullOrEmpty(x)).ToArray();
         int listOrder = 0;
         KonaDB db = new KonaDB();
         foreach (var pg in pages) {
             //subsonic style :)
             db.Update<Page>().Set(x => x.ListOrder == listOrder).Execute();
             listOrder++;
         }
     }
     return new EmptyResult();
 }
Esempio n. 19
0
        public void SaveWidgetOrder() {

            var commands = new List<DbCommand>();
            KonaDB db = new KonaDB();

            if (Request.Form["widgetid"] != null) {
                //pull out all widgetid's
                var ids = Request.Form.GetValues("widgetid").Where(x => !String.IsNullOrEmpty(x)).ToArray();
                int listOrder = 0;
                foreach (var id in ids) {
                    var widgetID = new Guid(id);
                    //subsonic style...
                    commands.Add(db.Update<Widget>().Set(x => x.ListOrder == listOrder).Where(x=>x.WidgetID==widgetID).GetCommand().ToDbCommand());
                    listOrder++;
                }
            }
            //transaction :)
            db.ExecuteTransaction(commands);

        }
Esempio n. 20
0
 public ActionResult OrderWidgets() {
     if (Request.Form["widgetid"]!=null) {
         //pull out all widgetid's
         var ids = Request.Form.GetValues("widgetid").Where(x=>!String.IsNullOrEmpty(x)).ToArray();
         int listOrder = 0;
         KonaDB db = new KonaDB();
         foreach (var id in ids) {
             var widgetID = new Guid(id);
             //subsonic style...
             db.Update<Widget>().Set(x => x.ListOrder == listOrder);
             listOrder++;
         }
     }
     return new EmptyResult();
 }