Exemple #1
0
        public JsonResult Lookup(string q_word, string primary_key, int per_page, int page_num)
        {
            using (var svc = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                var FilteredCategory = svc.Query <Category>()
                                       .Where(x => q_word == "" || x.CategoryName.Contains(q_word));


                var PagedFilter = FilteredCategory.OrderBy(x => x.CategoryName)
                                  .LimitAndOffset(per_page, page_num)
                                  .ToList();

                return(Json(
                           new
                {
                    cnt = FilteredCategory.Count()

                    , primary_key = PagedFilter.Select(x => x.CategoryId)

                    , candidate = PagedFilter.Select(x => x.CategoryName)

                    , cnt_page = PagedFilter.Count()

                    , attached = PagedFilter.Select(x =>
                                                    new[]
                    {
                        new string[] { "Code", x.CategoryCode },
                        new string[] { "Ranking", x.Ranking.ToString() }
                    }
                                                    )
                }
                           ));
            } //using
        }     //Lookup
        //
        // GET: /Home/

        public ViewResult Index()
        {
            using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                return(View(s.Query <Product>().OrderBy(x => x.ProductName).Fetch(x => x.Category).ToList()));
            }
        }
 public ActionResult InputEdit(int id)
 {
     using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
     {
         var p = s.Get <Product>(id);
         return(View("Input", p));
     }
 }
 public ActionResult Delete(int PurchasedId)
 {
     using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
     {
         s.Delete(s.Load <Purchased>(PurchasedId));
         s.Flush();
         return(RedirectToAction("Index"));
     }
 }
 public ViewResult DeletePreview(int id)
 {
     using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
     {
         return(View(
                    s.Query <Purchased>().Fetch(x => x.Product).ThenFetch(x => x.Category)
                    .Where(x => x.PurchasedId == id).Single()));
     }
 }
        public JsonResult xLookup(string cascaded_word, string q_word, string primary_key, int per_page, int page_num)
        {
            using (var svc = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                int categoryId = 0;

                bool isNumber = int.TryParse(cascaded_word, out categoryId);



                var FilteredProduct = svc.Query <Product>()
                                      .Where(x =>
                                             (

                                                 categoryId == 0
                                                 ||
                                                 (categoryId != 0 && x.Category.CategoryId == categoryId)

                                             )

                                             &&

                                             (q_word == "" || x.ProductName.Contains(q_word))

                                             );


                var PagedFilter = FilteredProduct.OrderBy(x => x.ProductName)
                                  .LimitAndOffset(per_page, page_num)
                                  .Fetch(x => x.Category)
                                  .ToList();

                return(Json(
                           new
                {
                    cnt = FilteredProduct.Count()

                    , primary_key = PagedFilter.Select(x => x.ProductId)

                    , candidate = PagedFilter.Select(x => x.ProductName)

                    , cnt_page = PagedFilter.Count()

                    , attached = PagedFilter.Select(x =>
                                                    new[]
                    {
                        new string[] { "Product Code", x.ProductCode },
                        new string[] { "Category Code", x.Category.CategoryCode },
                        new string[] { "Category", x.Category.CategoryName }
                    }
                                                    )
                }
                           ));
            } //using
        }     //CascadedFromCategoryLookup
 public ActionResult Input(PurchasedInputViewModel p)
 {
     if (ModelState.IsValid)
     {
         using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
         {
             s.Merge(p.Purchased);
             s.Flush();
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(View(p));
     }
 }
        public ViewResult InputEdit(int id)
        {
            using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                var l = s.Get <Purchased>(id);

                var px = new PurchasedInputViewModel
                {
                    MostSellingProductAdvisory = "Did you know Bumble Bee car is a fast-selling car?",
                    CategoryId = l.Product.Category.CategoryId,
                    Purchased  = l
                };

                return(View("Input", px));
            }
        }
        public string Caption(string q_word)
        {
            using (var svc = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                int  productId;
                bool isOk = int.TryParse(q_word, out productId);


                return
                    (isOk ?
                     svc.Query <Product>()
                     .Where(x => x.ProductId == productId)
                     .Select(x => x.ProductName)
                     .SingleOrDefault()
                    : "");
            }
        } //Caption
Exemple #10
0
        public string Caption(string q_word)
        {
            using (var svc = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                if (string.IsNullOrEmpty(q_word))
                {
                    return("");
                }

                int  categoryId;
                bool isOk = int.TryParse(q_word, out categoryId);


                return
                    (isOk ?
                     svc.Query <Category>()
                     .Where(x => x.CategoryId == categoryId)
                     .Select(x => x.CategoryName)
                     .SingleOrDefault()
                    : "");
            }
        }
        //
        // GET: /Purchased/

        public ViewResult Index()
        {
            using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                return(View(
                           s.Query <Purchased>()
                           // must do paging here
                           .Fetch(x => x.Product).ThenFetch(x => x.Category)


                           .ToList()
                           .Select(x =>
                                   new PurchasedViewModel
                {
                    PurchasedId = x.PurchasedId,
                    ProductName = x.Product.ProductName,
                    CategoryName = x.Product.Category.CategoryName,
                    Quantity = x.Quantity,
                    PurchasedBy = x.PurchasedBy
                }
                                   )
                           ));
            }
        }// Index