コード例 #1
0
        public ActionResult Input(CategoryModel model)
        {
            if (ModelState.IsValid)
            {
                Category category = null;
                try
                {
                    if (model.Id > 0)
                        category = _categoryService.Find(model.Id);
                    else
                        category = new Category() { CreatedDate = DateTime.Now };

                    #region Set value for category entity
                    category.Name = model.Name;
                    category.Alias = model.Alias;
                    category.Brief = model.Brief;
                    category.Description = model.Description;
                    category.IsActive = model.IsActive;
                    category.IsFeature = model.IsFeature;
                    category.DisplayOrder = model.DisplayOrder;
                    category.Thumbnail = model.Thumbnail != null ? model.Thumbnail : "default.jpg";
                    category.RootId = model.RootId;//
                    //category.HowIt = model.HowIt;
                    //category.KeyBenefit = model.KeyBenefit;
                    //category.Solution = model.Solution;
                    category.EnableGallery = model.EnableGallery;
                    //category.EnablePrintCapbility = model.EnablePrintCapbility;
                    category.UpdatedDate = DateTime.Now;
                    #endregion

                    #region Perform save data
                    if (model.Id <= 0)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            _categoryService.Insert(category);
                            _unitOfWork.SaveChanges();
                            scope.Complete();
                        }
                    }
                    else
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            _categoryService.Update(category);
                            _unitOfWork.SaveChanges();
                            scope.Complete();
                        }
                    }

                    return Json(new { Status = ResultStatus.Success, Message = StringTable.DataSaveSuccess });
                    #endregion
                }
                catch
                {
                    return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess });
                }
            }
            else
            {
                return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess });
            }
        }
コード例 #2
0
        public ActionResult CategoryDetail(string categoryAlias = "")
        {
            if (string.IsNullOrEmpty(categoryAlias))
            {
                return RedirectToAction("Index");
            }

            var categoryKey = string.Format(CATEGORY_BY_ALIAS_KEY, categoryAlias);
            var model = HgtCache.Get<CategoryModel>(categoryKey);
            if (model == null)
            {
                model = new CategoryModel();
                var category = _categoryService.GetCategoryByAlias(categoryAlias);
                if (category != null)
                {
                    model = category.ToModel();

                    #region products
                    // get product list
                    var productKey = string.Format(PRODUCT_BY_CATEGORYID_KEY, model.Id);
                    var products = HgtCache.Get<List<Product>>(productKey);
                    if (products == null)
                    {
                        products = _productService.GetListProductsByCategoryId(model.Id, false);
                        HgtCache.Insert(productKey, products);
                    }
                    model.Products = products;

                    #endregion

                    #region gallery

                    // get gallery image
                    var galleryImageKey = string.Format(CATEGORY_GALLERY_PRODUCTID_BY_TYPE_KEY, model.Id, (int)GalleryType.ImageAndVideo);
                    var galleryImage = new List<GalleryDetail>();
                    galleryImage = HgtCache.Get<List<GalleryDetail>>(galleryImageKey);
                    if (galleryImage == null)
                    {
                        galleryImage = _galleryService.GetListGalleryDetailByObjectId(model.Id, (int)GalleryCategory.Category, (int)GalleryType.ImageAndVideo);
                        HgtCache.Insert(galleryImageKey, galleryImage);
                    }
                    model.Galleries = galleryImage;
                    model.TotalGallery = galleryImage.Count;

                    #endregion

                    #region print capabilities

                    // get gallery print
                    var galleryPrintKey = string.Format(CATEGORY_GALLERY_PRODUCTID_BY_TYPE_KEY, model.Id, (int)GalleryType.PrintCapbility);
                    var galleryPrint = new List<GalleryDetail>();
                    galleryPrint = HgtCache.Get<List<GalleryDetail>>(galleryPrintKey);
                    if (galleryPrint == null)
                    {
                        galleryPrint = _galleryService.GetListGalleryDetailByObjectId(model.Id, (int)GalleryCategory.Category, (int)GalleryType.PrintCapbility);
                        HgtCache.Insert(galleryPrintKey, galleryPrint);
                    }
                    model.Prints = galleryPrint;
                    model.TotalPrint = galleryPrint.Count;

                    #endregion
                }
                HgtCache.Insert(categoryKey, model);
            }
            return View(model);
        }