public ActionResult Edit(ViewCategoryEdit shopCategory)
        {
            if (ModelState.IsValid)
            {
                // сохранение
                ShopCategory category   = db.ShopCategories.Find(shopCategory.Id);;
                bool         changeName = false;
                if (category.Name != shopCategory.Name)
                {
                    category.Name = shopCategory.Name;
                    changeName    = true;
                }

                if (shopCategory.Alias == null || changeName)
                {
                    category.Alias = Translit.TranslitString(shopCategory.Name);
                }
                else
                {
                    category.Alias = shopCategory.Alias;
                }
                category.Description     = shopCategory.Description;
                category.ParentId        = shopCategory.SelectedId;
                db.Entry(category).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            // создание выпадающего списка родительских категорий
            shopCategory.CategoriesList = new SelectList(ParentListForCurrentCategory(shopCategory.Id), "Id", "Name", shopCategory.SelectedId);
            return(View(shopCategory));
        }
        public async Task AddFile(ShopCategory viewModel, IFormFile file)
        {
            string subPath = @"wwwroot\uploaded_files"; // Your code goes here

            if (file != null && file.Length > 0)
            {
                DirectoryInfo di       = Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), subPath));
                var           filePath = Path.Combine(Directory.GetCurrentDirectory(), subPath, file.FileName);
                // If file with same name exists delete it
                //if (System.IO.File.Exists(file.FileName))
                //{
                //    System.IO.File.Delete(file.FileName);
                //}

                // Create new local file and copy contents of uploaded file
                //using (var localFile = System.IO.File.OpenWrite(filePath))
                using (var uploadedFile = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(uploadedFile);
                }


                viewModel.Hero = file.FileName;
            }
        }
        public ActionResult SaveShopCategory(ShopCategory shopCategory)
        {
            string status = "fail";
            string msg    = "保存失败!";

            if (shopCategory != null)
            {
                msg = Validate.ValidateString(new CustomValidate
                {
                    FieldName  = "分类名称",
                    FieldValue = shopCategory.CategoryName,
                    IsRequired = true,
                    MaxLength  = 100
                });

                if (msg == null)
                {
                    shopCategory.CreateTime = shopCategory.ID > 0 ? shopCategory.CreateTime : DateTime.Now;
                    int result = shopCategory.ID > 0 ? OperateContext.Current.BLLSession.IShopCategoryBLL.Modify(shopCategory) : OperateContext.Current.BLLSession.IShopCategoryBLL.Add(shopCategory);
                    if (result == 1)
                    {
                        status = "ok";
                        msg    = "保存成功!";
                    }
                }
            }

            return(OperateContext.Current.RedirectAjax(status, msg, null, null));
        }
Beispiel #4
0
        /// <summary>
        /// Method add category to shop
        /// <summary>
        /// <param name="shopCategory">ShopCategory</param>
        /// <returns>void</returns>
        public async Task AddCategoryToShopAsync(ShopCategory shopCategory)
        {
            var shop = await SingleShopAsync(shopCategory.ShopId);

            var category = await categoryRepository.SingleCategoryAsync(shopCategory.CategoryId);

            if (category.Level != 1)
            {
                throw new LevelShopCategoryException("Category' level must be 1.");
            }

            var check = await dbContext.Shops.Where(s => s.ShopCategory.Any(u => u.ShopId == shop.Id)).Where(s => s.ShopCategory.Any(u => u.CategoryId == category.Id)).ToListAsync();

            if (check.Count > 0)
            {
                throw new UniqShopException("Current category has already been in current shop.");
            }

            var sc = new ShopCategory()
            {
                ShopId = shop.Id, CategoryId = category.Id
            };
            await Task.Run(() => shop.ShopCategory.Add(sc));

            await SaveAsync();
        }
Beispiel #5
0
        public void InitTab(ShopCategory cat)
        {
            _category = cat;

            int rowsRequired = 1 + (_category.ItemsInCategory.Count / ShopController.Instance.ItemsPerRow);

            _tabRows = new Transform[rowsRequired];

            for (int i = 0; i < rowsRequired; i++)
            {
                _tabRows[i] = Instantiate(_shopRowPrefab, _content);
            }

            int currentRowIndex = 0;

            for (int index = 0; index < _category.ItemsInCategory.Count; index++)
            {
                BaseBuyable  baseBuyable  = _category.ItemsInCategory[index];
                ShopItemView shopItemView = Instantiate(_shopItemPrefab, _tabRows[currentRowIndex]);
                shopItemView.Populate(baseBuyable);

                if ((index > 0) && ((index + 1) % ShopController.Instance.ItemsPerRow == 0))
                {
                    currentRowIndex++;
                }
            }
        }
        //==========================================================



        //==========================================================
        // инфо о категории
        // GET: AdminPanel/Categories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopCategory shopCategory = db.ShopCategories.Find(id);

            if (shopCategory == null)
            {
                return(HttpNotFound());
            }

            // заполнение модели представления
            ViewCategoryDetail category = new ViewCategoryDetail
            {
                Name        = shopCategory.Name,
                Alias       = shopCategory.Alias,
                Description = shopCategory.Description
            };

            if (shopCategory.ParentId != null)
            {
                category.Parent = db.ShopCategories.Find(shopCategory.ParentId).Name;
            }
            // подсчет подкатегорий
            category.CountChildCategories = ChildCategoriesCount(shopCategory.Id);
            // подсчет товаров
            category.CountProducts = 0;
            return(View(category));
        }
        public async Task <IActionResult> Create(ShopCategory viewModel, IFormFile file)
        {
            if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                await _shopCategoryService.AddFile(viewModel, file);

                var Id = await _shopCategoryService.Add(viewModel);

                if (!String.IsNullOrEmpty(Request.Form["continue"]))
                {
                    return(RedirectToAction("Edit", new { Id = Id }));
                }
                if (!String.IsNullOrEmpty(Request.Form["new"]))
                {
                    return(RedirectToAction(nameof(Create)));
                }
                return(RedirectToAction(nameof(Index)));
            }
            var categories = await _shopCategoryService.GetAll();

            ViewBag.Categories = new SelectList(categories.ToList(), "Id", "Title", viewModel.ParentId);

            return(View(viewModel));
        }
        private static void FixSubMenuPath(List <ShopCategory> data, ShopCategory parent, List <ShopCategory> updateList)
        {
            var layer = (from a in data where a.ParentId == parent.Id select a);

            foreach (ShopCategory menu in layer)
            {
                string curPath = parent.Path + "/" + parent.Id;
                if (parent.RootId != null)
                {
                    int curRootId = parent.RootId == 0 ? parent.Id : parent.RootId.Value;
                    if (parent.Depth != null)
                    {
                        int curDepth = parent.Depth.Value + 1;

                        if (!(menu.Depth == curDepth && menu.RootId == curRootId && menu.Path == curPath))
                        {
                            menu.Depth  = curDepth;
                            menu.RootId = curRootId;
                            menu.Path   = curPath;

                            updateList.Add(menu);
                        }
                    }
                }
                FixSubMenuPath(data, menu, updateList);
            }
        }
        public ActionResult Create(ViewCategoryCreate shopCategory)
        {
            if (ModelState.IsValid)
            {
                // сохранение
                ShopCategory category = new ShopCategory();
                category.Name = shopCategory.Name;
                if (shopCategory.Alias == null)
                {
                    category.Alias = Translit.TranslitString(shopCategory.Name);
                }
                else
                {
                    category.Alias = shopCategory.Alias;
                }
                category.Description = shopCategory.Description;
                category.ParentId    = shopCategory.SelectedId;
                db.ShopCategories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            // создание выпадающего списка родительских категорий
            List <ShopCategory> categories = db.ShopCategories.OrderBy(c => c.Name).ToList();

            shopCategory.CategoriesList = new SelectList(categories, "Id", "Name", shopCategory.SelectedId);
            return(View(shopCategory));
        }
        //==========================================================



        //==========================================================
        // редактирование категории
        // GET: AdminPanel/Categories/Edit/5
        public ActionResult Edit(int?id)
        {
            // проверка входящего Id
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            // поиск модели в БД
            ShopCategory shopCategory = db.ShopCategories.Find(id);

            if (shopCategory == null)
            {
                return(HttpNotFound());
            }

            // создание модели представления
            ViewCategoryEdit category = new ViewCategoryEdit
            {
                Id          = shopCategory.Id,
                Name        = shopCategory.Name,
                Alias       = shopCategory.Alias,
                Description = shopCategory.Description,
                SelectedId  = shopCategory.ParentId
            };

            // создание выпадающего списка родительских категорий с выбранным значением по умолчанию
            category.CategoriesList = new SelectList(ParentListForCurrentCategory(category.Id), "Id", "Name", category.SelectedId);
            return(View(category));
        }
        public void Setup(ShopCategory category)
        {
            m_Category = category;

            string content = string.Empty;

            switch (m_Category)
            {
            case ShopCategory.AAA:
                content = "AAA";
                break;

            case ShopCategory.BBB:
                content = "BBB";
                break;

            case ShopCategory.CCC:
                content = "CCC";
                break;

            case ShopCategory.DDD:
                content = "DDD";
                break;

            default:
                break;
            }
            m_Text.text = content;
        }
        public ActionResult Edit(FormCollection fc, ShopCategory shopcategory)
        {
            if (this.ModelState.IsValid)
            {
                var origShopCategory = this.db.ShopCategories.Find(shopcategory.CategoryId);

                origShopCategory.Name        = shopcategory.Name;
                origShopCategory.Description = shopcategory.Description;

                int newParentCategoryId;
                var newParentCategory = int.TryParse(fc["NewParentCategoryId"], out newParentCategoryId)
                                                  ? this.db.ShopCategories.Find(newParentCategoryId)
                                                  : null;
                if (newParentCategory == null)
                {
                    if (origShopCategory.ParentCategory != null)
                    {
                        origShopCategory.ParentCategory.Subcategories.Remove(origShopCategory);
                    }
                }
                else
                {
                    origShopCategory.ParentCategory = newParentCategory;
                }

                this.db.SaveChanges();

                return(this.RedirectToAction("Index"));
            }

            this.ViewBag.CategorySelectList = this.GetCategorySelectList(shopcategory);
            return(this.View(shopcategory));
        }
Beispiel #13
0
        private void InitCategories(ShopCategory[] setupCategories)
        {
            // init array
            _shopTabs = new ShopTabView[setupCategories.Length];

            // loop over all available categories - they come from the setup, see ShopCategory
            for (int index = 0; index < setupCategories.Length; index++)
            {
                // the current category
                ShopCategory setupCategory = setupCategories[index];

                // spawn it
                ShopTabView tabView = Instantiate(_tabViewPrefab);
                tabView.InitTab(setupCategory);
                tabView.Hide();
                _shopTabs[index] = tabView;

                // spawn the button opening the tab
                ShopTabButton tabButton = Instantiate(_tabButtonPrefab);
                tabButton.Init(index, setupCategory.name);

                // add tab to the screen
                _screen.AddTab(tabView, tabButton);
            }
        }
        public async Task Add(ShopCategory shopCategory)
        {
            var dbContext = new LMDbContext();
            await dbContext.ShopCategories.AddAsync(shopCategory);

            await dbContext.SaveChangesAsync();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ShopCategory shopcategory = this.db.ShopCategories.Find(id);

            this.db.ShopCategories.Remove(shopcategory);
            this.db.SaveChanges();
            return(this.RedirectToAction("Index"));
        }
        public async Task Update(ShopCategory shopCategory)
        {
            var dbContext            = new LMDbContext();
            var shopCategoryToUpdate = await dbContext.ShopCategories.FirstOrDefaultAsync(c => c.Id == shopCategory.Id);

            shopCategoryToUpdate = shopCategory;
            await dbContext.SaveChangesAsync();
        }
        //
        // GET: /ShopCategory/Details/5

        public ActionResult Details(int id = 0)
        {
            ShopCategory shopcategory = this.db.ShopCategories.Find(id);

            if (shopcategory == null)
            {
                return(this.HttpNotFound());
            }
            return(this.View(shopcategory));
        }
Beispiel #18
0
        public async Task <ShopCategory> Post(ShopCategory shopCategory)
        {
            if (ModelState.IsValid)
            {
                await shopDatabaseService.Add(shopCategory);

                return(shopCategory);
            }
            throw new Exception();
        }
        public async Task <ShopCategory> Add(ShopCategory viewModel)
        {
            var model = _mapper.Map <ShopCategoryEntity>(viewModel);

            _context.ShopCategories.Add(model);
            await _context.SaveChangesAsync();

            _mapper.Map(model, viewModel);
            return(viewModel);
        }
        //
        // GET: /ShopCategory/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ShopCategory shopcategory = this.db.ShopCategories.Find(id);

            if (shopcategory == null)
            {
                return(this.HttpNotFound());
            }

            this.ViewBag.CategorySelectList = this.GetCategorySelectList(shopcategory);
            return(this.View(shopcategory));
        }
Beispiel #21
0
        public virtual ActionResult Categories(int id)
        {
            var viewModel = new ShopCategory();

            viewModel.Category = db.Categories.First(c => c.Id == id);
            viewModel.Products = db.Products
                                 .Where(p => p.IsPublished &&
                                        p.CategoryId == id &&
                                        p.Available > 0) // Nur verfügbare Produkte anzeigen.
                                 .ToArray();
            return(View(viewModel));
        }
        //==========================================================

        //==========================================================
        // вспомогательный метод
        // поиск дочерних категорий
        // и удаление их
        private void DeleteChileCategories(ShopCategory category)
        {
            List <ShopCategory> childCategories = db.ShopCategories
                                                  .Where(c => c.ParentId == category.Id).OrderBy(c => c.Name).ToList();

            foreach (ShopCategory childCategory in childCategories)
            {
                DeleteChileCategories(childCategory);
                db.ShopCategories.Remove(childCategory);
                db.SaveChanges();
            }
        }
        public ActionResult Edit([Bind(Include = "Id,Name,Description,CreatedAt,CreatedBy,LastModifiedAt,LastModifiedBy,IsActive")] ShopCategory shopCategory)
        {
            if (ModelState.IsValid)
            {
                shopCategory.LastModifiedAt = DateTime.Now;
                shopCategory.LastModifiedBy = 0;

                db.Entry(shopCategory).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(shopCategory));
        }
        public async Task <ShopCategory> Update(ShopCategory viewModel)
        {
            if (viewModel.Id == null)
            {
                throw new ArgumentNullException(nameof(viewModel.Id));
            }
            var data = await _context.ShopCategories.FirstOrDefaultAsync(c => c.Id == viewModel.Id);

            _mapper.Map(viewModel, data);
            _context.Update(data);
            await _context.SaveChangesAsync();

            return(viewModel);
        }
        // GET: ShopCategory/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopCategory shopCategory = db.ShopCategories.Find(id);

            if (shopCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(shopCategory));
        }
        private SelectList GetCategorySelectList(ShopCategory category = null)
        {
            var parentCategoryId = category == null
                                       ? null
                                       : (category.ParentCategory == null
                                              ? null
                                              : (int?)category.ParentCategory.CategoryId);

            return(new SelectList(
                       this.db.ShopCategories,
                       "CategoryId",
                       "Name",
                       parentCategoryId));
        }
 public ShopItemCard(uint cardGUID, CardView cardView, ShopCategory category, ShopItemType itemType, byte tier, string[] sortingNames, int sortingWeight, Price buyPrice, Price upgradePrice, Price sellPrice, Faction faction, bool canBeSold)
     : base(cardGUID, cardView)
 {
     Category      = category;
     ItemType      = itemType;
     Tier          = tier;
     SortingNames  = sortingNames;
     SortingWeight = sortingWeight;
     BuyPrice      = buyPrice;
     UpgradePrice  = upgradePrice;
     SellPrice     = sellPrice;
     Faction       = faction;
     CanBeSold     = canBeSold;
 }
        public async Task <IActionResult> Edit(int Id, ShopCategory viewModel, IFormFile file)
        {
            if (Id == null)
            {
                return(NotFound());
            }

            if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _shopCategoryService.AddFile(viewModel, file);

                    await _shopCategoryService.Update(viewModel);

                    if (!String.IsNullOrEmpty(Request.Form["continue"]))
                    {
                        return(RedirectToAction("Edit", new { Id = Id }));
                    }
                    if (!String.IsNullOrEmpty(Request.Form["new"]))
                    {
                        return(RedirectToAction(nameof(Create)));
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                catch (DBConcurrencyException)
                {
                    var exists = await Exists(viewModel.Id);

                    if (!exists)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            var categories = await _shopCategoryService.GetAll();

            ViewBag.Categories = new SelectList(categories.ToList(), "Id", "Title", viewModel.ParentId);
            return(View(viewModel));
        }
        //==========================================================



        //==========================================================
        // вспомогательный метод
        // перегрузка метода
        private List <ShopCategory> FindChildCategories(ShopCategory category)
        {
            List <ShopCategory> childCategories = db.ShopCategories
                                                  .Where(c => c.ParentId == category.Id).OrderBy(c => c.Name).ToList();

            List <ShopCategory> childList = new List <ShopCategory>();

            childList.Add(category);

            foreach (ShopCategory childCategory in childCategories)
            {
                childList.AddRange(FindChildCategories(childCategory));
            }
            return(childList);
        }
        public ActionResult Create([Bind(Include = "Id,Name,Description,CreatedAt,CreatedBy,LastModifiedAt,LastModifiedBy,IsActive")] ShopCategory shopCategory)
        {
            if (ModelState.IsValid)
            {
                shopCategory.CreatedAt      = DateTime.Now;
                shopCategory.CreatedBy      = 0;
                shopCategory.LastModifiedAt = DateTime.Now;
                shopCategory.LastModifiedBy = 0;
                shopCategory.IsActive       = true;

                db.ShopCategories.Add(shopCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shopCategory));
        }
Beispiel #31
0
        //public ScrapeStatus Status
        //{
        //    get
        //    {
        //        return (ScrapeStatus)StatusCode;
        //    }
        //    set
        //    {
        //        StatusCode = (int)value;
        //    }
        //}
        public ShopProduct CreateShopProduct(ShopCategory shopCategory)
        {
            var shopProduct = new ShopProduct();
            shopProduct.Title = this.Title;
            shopProduct.Description = this.Description;
            shopProduct.Price = this.Price;
            shopProduct.IsSale = this.IsSale;
            shopProduct.DiscountPrice = this.DiscountPrice;

            shopProduct.Category = shopCategory;

            this.ShopProduct = shopProduct;

            Context.Inst.ShopProductSet.Add(shopProduct);
            Context.Save();

            foreach (var image in this.Images)
            {
                shopProduct.AddImage(image.LocalPath);
            }

            return shopProduct;
        }
Beispiel #32
0
 private void addHeadlineShop(ShopCategory category)
 {
     string cat = category.ToString();
     if (_headlineShops.Any(m => m.FirstCategory == cat)) return;
     var shoeShops = _allShops.Where(m => !_headlineShops.Contains(m) && m.FirstCategory == cat).ToList();
     shoeShops.OrderBy(m => this.rand.Next());
     int shoeShopsCount = shoeShops.Count;
     for (int i = 0; i < shoeShopsCount && i < 1; i++)
     {
         _headlineShops.Add(shoeShops[i]);
         reportShopDisplay(shoeShops[i]);
     }
 }
        protected ShopCategory GetObject(DataRow dr)
        {
            ShopCategory objShopCategory = new ShopCategory();
            objShopCategory.Id = (dr["Id"] == DBNull.Value) ? 0 : (Int32)dr["Id"];
            objShopCategory.Category = (dr["Category"] == DBNull.Value) ? "" : (String)dr["Category"];
            objShopCategory.ServiceCharge = (dr["ServiceCharge"] == DBNull.Value) ? 0 : (Decimal)dr["ServiceCharge"];
            objShopCategory.Description = (dr["Description"] == DBNull.Value) ? "" : (String)dr["Description"];
            objShopCategory.IsActive = (dr["IsActive"] == DBNull.Value) ? false : (Boolean)dr["IsActive"];
            objShopCategory.LastModified = (dr["LastModified"] == DBNull.Value) ? DateTime.MinValue : (DateTime)dr["LastModified"];
            objShopCategory.ModifiedBy = (dr["ModifiedBy"] == DBNull.Value) ? 0 : (Int32)dr["ModifiedBy"];
            objShopCategory.MiscBill = (dr["MiscBill"] == DBNull.Value) ? 0 : (Decimal)dr["MiscBill"];

            return objShopCategory;
        }