Beispiel #1
0
 public ActionResult Edit(GoodsCategoryViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         using (var db = new SmDbContext())
         {
             var entity = db.GoodsCategories.FirstOrDefault(x => x.Id == model.Id);
             if (entity == null)
             {
                 entity = new GoodsCategory();
                 db.GoodsCategories.Add(entity);
             }
             entity.Name        = model.Name;
             entity.Description = model.Description;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Name", ex);
         return(View(model));
     }
 }
Beispiel #2
0
        public List <GoodsCategory> findByWhere(string @where)
        {
            List <GoodsCategory> list = null;
            String sql = String.Format("SELECT * FROM goods_categories WHERE {0} ORDER BY id DESC", where);

            using (MySqlDataReader rdr = Tools.MySqlHelper.ExecuteReader(Tools.MySqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql))
            {
                while (true)
                {
                    if (list == null)
                    {
                        list = new List <GoodsCategory>();
                    }

                    GoodsCategory category = fillGoodsCategory(rdr);
                    if (category == null)
                    {
                        break;
                    }
                    list.Add(category);
                }
            }

            return(list);
        }
Beispiel #3
0
        public ActionResult Create(Guid?parentId)
        {
            //商品分类
            var categories = _goodsService.GetCategories();

            if (categories == null || categories.Count == 0)
            {
                categories = new List <GoodsCategory>();
            }
            categories.Add(new GoodsCategory {
                Id = Guid.Empty, ParentId = Guid.Empty, Name = "顶级"
            });
            ViewBag.CategoriesJson = categories.Select(me => new { id = me.Id, pId = me.ParentId, name = me.Name }).ToList().ToJson();
            ViewBag.GoodsType      = _currencyService.GetList <GoodsType>(t => t.Enabled);


            GoodsCategory parentCategory = null;

            if (parentId != null)
            {
                parentCategory = _currencyService.GetSingleById <GoodsCategory>(parentId);
            }
            ViewBag.ParentCategory = parentCategory;

            return(View("Edit", new GoodsCategory()));
        }
Beispiel #4
0
        public async Task <ResultViewModel> Update([FromBody] UpdateCategoryParams updateCategoryParams)
        {
            ResultViewModel msg = UpdateCategoryParamsValidator.Validate(updateCategoryParams);

            if (msg.Code != ResultCode.Success)
            {
                return(msg);
            }

            GoodsCategory goodsCategory = await goodsCategoryBusiness.Get(this.CurrentAuthShopId(), updateCategoryParams.Id);

            if (goodsCategory == null)
            {
                return new ResultViewModel {
                           Code = ResultCode.Fail, Message = "分组不存在"
                }
            }
            ;

            goodsCategory.Name      = updateCategoryParams.Name;
            goodsCategory.ShowIndex = updateCategoryParams.ShowIndex;
            goodsCategoryBusiness.Update(goodsCategory);
            return(new ResultViewModel {
                Code = ResultCode.Success, Message = "操作成功"
            });
        }
    }
Beispiel #5
0
        public CatalogPage(GoodsCategory item, List <string> GoodsNameCart1, List <CartGoods> GoodsCartList1, List <int> GoodsPiece)
        {
            InitializeComponent();
            GoodsNameCart = GoodsNameCart1;
            GoodsCartList = GoodsCartList1;
            Piece         = GoodsPiece;
            AddGoodsCategory();
            AddGoodsInformation();
            AddGoodsImage();
            AddGoodsToCatalog();
            DisplayDatabase();
            GetValueForShopCartInfo(GoodsCartList);


            List <Goods>            goods1            = GoodsDatabase.GetItemsNotDoneAsync().Result;
            List <GoodsCategory>    goodscategory1    = GoodsCategoryDatabase.GetItemsNotDoneAsync().Result;
            List <GoodsInformation> goodsinformation1 = GoodsInformationDatabase.GetItemsNotDoneAsync().Result;
            List <GoodsImage>       goodsimage1       = GoodsImageDatabase.GetItemsNotDoneAsync().Result;

            var query = from goods in goods1
                        join goodscategory in goodscategory1 on goods.GoodsCategoryID equals goodscategory.GoodsCategoryID
                        where goodscategory.Category == item.Category
                        join goodsinformation in goodsinformation1 on goods.GoodsInformationID equals goodsinformation.GoodsInformationID
                        join goodsimage in goodsimage1 on goods.GoodsImageID equals goodsimage.ImageID
                        select new { Name = goods.Name, Price = goods.Price, Category = goodscategory.Category, Type = goodsinformation.Type, ImageName = goodsimage.ImageName };

            GoodsListview.ItemsSource = query;
        }
Beispiel #6
0
        public List <GoodsCategory> findAll()
        {
            List <GoodsCategory> list = null;
            String sql = "SELECT * FROM goods_categories";

            using (MySqlDataReader rdr = Tools.MySqlHelper.ExecuteReader(Tools.MySqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql))
            {
                while (true)
                {
                    if (list == null)
                    {
                        list = new List <GoodsCategory>();
                    }

                    GoodsCategory category = fillGoodsCategory(rdr);
                    if (category == null)
                    {
                        break;
                    }
                    list.Add(category);
                }
            }

            return(list);
        }
Beispiel #7
0
        public ActionResult Edit(Guid categoryId)
        {
            //商品分类
            var categories = _goodsService.GetCategories();

            if (categories == null || categories.Count == 0)
            {
                throw new BntWebCoreException("商品分类异常");
            }

            categories.Add(new GoodsCategory {
                Id = Guid.Empty, ParentId = Guid.Empty, Name = "顶级"
            });
            RemoveChild(categories, categoryId);
            ViewBag.CategoriesJson = categories.Select(me => new { id = me.Id, pId = me.ParentId, name = me.Name }).ToList().ToJson();
            ViewBag.GoodsType      = _currencyService.GetList <GoodsType>(t => t.Enabled);


            var category = _currencyService.GetSingleById <GoodsCategory>(categoryId);

            GoodsCategory parentCategory = null;

            if (category != null && category.ParentId != Guid.Empty)
            {
                parentCategory = _currencyService.GetSingleById <GoodsCategory>(category.ParentId);
            }
            ViewBag.ParentCategory = parentCategory;


            return(View(category));
        }
Beispiel #8
0
        public async Task <IActionResult> EditCategory(Guid id, [Bind("Id,SerialCode,Name")] GoodsCategory goodsCategory)
        {
            if (id != goodsCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(goodsCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GoodsCategoryExists(goodsCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(goodsCategory));
        }
        public Guid CreateCategory(GoodsCategory model)
        {
            bool result;

            using (var dbContext = new MallDbContext())
            {
                model.Id = KeyGenerator.GetGuidKey();
                if (model.ParentId == Guid.Empty)
                {
                    model.MergerId = model.Id.ToString();
                    model.Level    = 1;
                }
                else
                {
                    var parentCategory = _currencyService.GetSingleById <GoodsCategory>(model.ParentId);
                    model.MergerId = parentCategory.MergerId + "," + model.Id;
                    model.Level    = parentCategory.Level + 1;
                }
                dbContext.GoodsCategories.Add(model);

                result = dbContext.SaveChanges() > 0;
            }

            if (!result)
            {
                return(Guid.Empty);
            }
            Logger.Operation($"创建商品分类-{model.Name}:{model.Id}", MallModule.Instance, SecurityLevel.Normal);
            return(model.Id);
        }
Beispiel #10
0
        public List <GoodsCategory> SelectAll()
        {
            List <GoodsCategory> list = new List <GoodsCategory>();
            GoodsCategory        s    = new GoodsCategory();

            s.CategoryId   = "-1";
            s.CategoryName = "所有类型";
            list.Add(s);
            try
            {
                DataTable table = ExecuteDataTable(@"select * from goods_category");

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    GoodsCategory rt  = new GoodsCategory();
                    DataRow       row = table.Rows[i];
                    rt.CategoryId   = (string)row["id"];
                    rt.CategoryName = (string)row["category_name"];

                    list.Add(rt);
                }
            }
            catch (Exception ex)
            {
                JuYuan.utils.ErrorCatchUtil.showErrorMsg(ex);
            }

            return(list);
        }
Beispiel #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="category"></param>
 /// <param name="deleter"></param>
 public void DeleteGoodsCategory(GoodsCategory category, string deleter)
 {
     using (IDbConnection conn = DAOFactory.Instance.OpenConnection())
     {
         IGoodsCategoryDAO dao = DAOFactory.Instance.CreateGoodsCategoryDAO();
         dao.DeleteGoodsCategory(category.ID, conn);
     }
 }
Beispiel #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="category"></param>
 /// <param name="creator"></param>
 public void CreateGoodsCategory(GoodsCategory category, string creator)
 {
     using (IDbConnection conn = DAOFactory.Instance.OpenConnection())
     {
         IGoodsCategoryDAO dao = DAOFactory.Instance.CreateGoodsCategoryDAO();
         dao.InsertGoodsCategory(category, conn);
     }
 }
Beispiel #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="category"></param>
 /// <param name="modifier"></param>
 public void SaveGoodsCategory(GoodsCategory category, string modifier)
 {
     using (IDbConnection conn = DAOFactory.Instance.OpenConnection())
     {
         IGoodsCategoryDAO dao = DAOFactory.Instance.CreateGoodsCategoryDAO();
         dao.UpdateGoodsCategory(category, conn);
     }
 }
Beispiel #14
0
        /// <summary>
        /// Unsurprisingly, deletes goods category =(
        /// </summary>
        /// <param name="id">Goods category id</param>
        public void Delete(int id)
        {
            GoodsCategory goodsCategory = _context.GoodsCategories.FirstOrDefault(x => x.Id == id);

            if (goodsCategory != null)
            {
                _context.GoodsCategories.Remove(goodsCategory);
            }
        }
Beispiel #15
0
 /// <summary>
 ///     Gets all product with category which equals current that exists in warehouse
 /// </summary>
 public IEnumerable <Product> GetProductsByCategory(GoodsCategory category)
 {
     if (!Enum.IsDefined(typeof(GoodsCategory), category))
     {
         throw new InvalidEnumArgumentException(nameof(category), (int)category, typeof(GoodsCategory));
     }
     return(AvailableProducts.Where(product => product.Key.Category == category).Select(product => product.Key)
            .ToList());
 }
Beispiel #16
0
        public GoodsCategoryViewModel UpdateGoodsCategory(GoodsCategoryViewModel model)
        {
            GoodsCategory category = this._unitOfWork.GoodsCategoryRepository.GetGoodsCategoryById(model.Id);

            category.Name        = model.Name;
            category.GoodsTypeId = model.GoodsTypeId;
            this._unitOfWork.SaveChanges();
            return(category);
        }
Beispiel #17
0
        public OneLevelCategoryModel(GoodsCategory model)
        {
            Id   = model.Id;
            Name = model.Name;
            var fileService = HostConstObject.Container.Resolve <IStorageFileService>();
            var mainImage   = fileService.GetFiles(model.Id, MallModule.Key, "CategoryImage").FirstOrDefault();

            CategoryImage = mainImage?.Simplified();
        }
Beispiel #18
0
        public async Task <string> ModifyCategoryAsync([FromBody] GoodsCategory category)
        {
            category.UniqueId = category.UniqueId ?? SfraObject.GenerateId();
            await mongo.GoodsCategoryCollection.FindOneAndReplaceAsync <GoodsCategory>(x => x.UniqueId == category.UniqueId, category, new FindOneAndReplaceOptions <GoodsCategory, GoodsCategory> {
                IsUpsert = true
            });

            return(category.UniqueId);
        }
Beispiel #19
0
        /// <summary>
        /// 用于修改
        /// </summary>
        /// <param name="model"></param>
        public FrmGoodsCategory(GoodsCategory model)
        {
            InitializeComponent();
            this._Model = model;

            this.Text           = string.Format(this.Text, "修改");
            this.txtCode.Text   = model.Code;
            this.txtName.Text   = model.Name;
            this.txtRemark.Text = model.Remark;
        }
Beispiel #20
0
        public GoodsCategoryViewModel CreateGoodsCategory(GoodsCategoryViewModel model)
        {
            GoodsCategory category = new GoodsCategory();

            category.Name        = model.Name;
            category.GoodsTypeId = model.GoodsTypeId;
            this._unitOfWork.GoodsCategoryRepository.Create(category);
            this._unitOfWork.SaveChanges();
            return(category);
        }
        public Guid UpdateCategory(GoodsCategory model)
        {
            bool result;

            using (var dbContext = new MallDbContext())
            {
                if (model.ParentId == Guid.Empty)
                {
                    model.MergerId = model.Id.ToString();
                    model.Level    = 1;
                }
                else
                {
                    var parentCategory = _currencyService.GetSingleById <GoodsCategory>(model.ParentId);
                    model.MergerId = parentCategory.MergerId + "," + model.Id;
                    model.Level    = parentCategory.Level + 1;
                }
                var  oldCategory  = _currencyService.GetSingleById <GoodsCategory>(model.Id);
                bool parentChange = oldCategory.ParentId != model.ParentId;
                bool levelChange  = oldCategory.Level != model.Level;

                dbContext.Entry(model).State = EntityState.Modified;

                //父级变更
                if (parentChange)
                {
                    var idStr           = model.Id.ToString();
                    var childCategories = dbContext.GoodsCategories.Where(x => x.MergerId.Contains(idStr) && x.Id != model.Id);
                    foreach (var child in childCategories)
                    {
                        var mergerArr = child.MergerId.Split(new string[] { idStr }, StringSplitOptions.None);

                        child.MergerId = model.MergerId + mergerArr[1];

                        //等级发生变更
                        if (levelChange)
                        {
                            child.Level = child.MergerId.Split(',').Length;
                        }

                        dbContext.Entry(child).State = EntityState.Modified;
                    }
                }

                result = dbContext.SaveChanges() > 0;
            }


            if (!result)
            {
                return(Guid.Empty);
            }
            Logger.Operation($"更新商品分类-{model.Name}:{model.Id}", MallModule.Instance, SecurityLevel.Normal);
            return(model.Id);
        }
Beispiel #22
0
 public Task <int> SaveItemAsync(GoodsCategory item)
 {
     if (item.GoodsCategoryID != 0)
     {
         return(database.UpdateAsync(item));
     }
     else
     {
         return(database.InsertAsync(item));
     }
 }
Beispiel #23
0
 /// <summary>
 /// 累计某类商品销售额度
 /// </summary>
 /// <param name="cat">商品分类</param>
 /// <param name="item">被统计数据项</param>
 private void GetValue(GoodsCategory cat, ReportGoodsRank item)
 {
     for (int i = 0; i < lastRow.Cells.Count; i++)
     {
         if (Convert.ToInt32(lastRow.Cells[i].Tag) == cat.Id)
         {
             lastRow.Cells[i].Value = Convert.ToDecimal(lastRow.Cells[i].Value) + (cat.Name.Trim() == "刷卡" ? item.Count : item.Price);
             break;
         }
     }
 }
        /// <summary>
        /// 删除商品分类
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool DeleteCategory(GoodsCategory model)
        {
            var result = _currencyService.DeleteByConditon <GoodsCategory>(
                me => me.Id == model.Id);

            if (result > 0)
            {
                Logger.Operation($"删除商品分类-{model.Name}:{model.Id}", MallModule.Instance, SecurityLevel.Warning);
            }

            return(result > 0);
        }
        public async Task <ApiResult> CreateCategory(CategoryCreateDto input)
        {
            var goodsCategory = new GoodsCategory();

            goodsCategory.CreateOrUpdate(input.CategoryName, input.Sort);
            repository.Add(goodsCategory);
            if (await new UniqueGoodsCategoryNameSpecification(repository).IsSatisfiedBy(goodsCategory))
            {
                await unitofWork.CommitAsync();
            }
            return(ApiResult.Ok("商品分类创建成功"));
        }
Beispiel #26
0
        public GoodsCategory find(int id)
        {
            GoodsCategory category = null;
            String        sql      = String.Format("SELECT * FROM goods_categories WHERE id = {0}", id);

            using (MySqlDataReader rdr = Tools.MySqlHelper.ExecuteReader(Tools.MySqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql))
            {
                category = fillGoodsCategory(rdr);
            }

            return(category);
        }
        public void InsertGoodsCategory(GoodsCategory goodsCategory, IDbConnection conn, IDbTransaction trans)
        {
            string sql = @"
            INSERT INTO MD_GoodsCategory(GoodsCategoryCode,GoodsCategoryName,Actived) 
            VALUES(@GoodsCategoryCode,@GoodsCategoryName,@Actived)";
            List <SqlParameter> paramList = new List <SqlParameter>();

            paramList.Add(new SqlParameter("@GoodsCategoryCode", goodsCategory.Code));
            paramList.Add(new SqlParameter("@GoodsCategoryName", goodsCategory.Name));
            paramList.Add(new SqlParameter("@Actived", goodsCategory.Actived));
            DataAccessUtil.ExecuteNonQuery(sql, paramList, (SqlTransaction)trans);
        }
Beispiel #28
0
        /// <summary>
        /// 填充数据到表单文本控件,下拉框控件
        /// </summary>
        /// <param name="IsFill"></param>
        private void FillDataToCtrl(bool IsFill)
        {
            DBManager db     = DBManager.Instance();
            string    strSql = "select GoodsCategoryId,Description,FatherID from goods_category";

            //获取记录数据
            dt = db.GetDataTable(strSql);


            dtTemp.TableName = "GoodsCategory";
            if (dt != null)
            {
                dtTemp.Rows.Clear();
                DataRow[] dRows = dt.Select("fatherid = '0'");
                for (int i = 0; i < dRows.Length; i++)
                {
                    dtTemp.Rows.Add(dRows[i]["GoodsCategoryId"], dRows[i]["Description"], dRows[i]["FatherId"]);
                    InsertdtTemp(dRows[i]["GoodsCategoryId"].ToString(), "—");
                }



                DataRow df = dtTemp.NewRow();
                df["Description"]     = "---顶级分类---";
                df["GoodsCategoryId"] = "0";
                dtTemp.Rows.InsertAt(df, 0);
                ddlFather.DataSource     = dtTemp;
                ddlFather.DataTextField  = "Description";
                ddlFather.DataValueField = "GoodsCategoryId";
                ddlFather.DataBind();



                GoodsCategoryDB goodscatedb = new GoodsCategoryDB();

                if (IsFill)
                {
                    GoodsCategory goodscate = new GoodsCategory();
                    goodscatedb = goodscate.FindCate(strGoodsCategoryId);

                    //txtCateId.Text = Common.CCToEmpty(goodscatedb.GoodsCategoryId);
                    txtCateName.Text = Common.CCToEmpty(goodscatedb.Description);
                    //ddlFather.SelectedIndex = Convert.ToInt32(Common.CCToEmpty(goodscatedb.FatherId));
                    ddlFather.SelectedValue = goodscatedb.FatherId;
                }
                else
                {
                    goodscatedb             = new GoodsCategoryDB();
                    ddlFather.SelectedValue = strGoodsFatherCategoryId;
                    //this.txtCateId.Enabled = true;
                }
            }
        }
Beispiel #29
0
        public async Task <IActionResult> CreateCategory([Bind("Id,SerialCode,Name")] GoodsCategory goodsCategory)
        {
            if (ModelState.IsValid)
            {
                goodsCategory.Id = Guid.NewGuid();
                _context.Add(goodsCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(goodsCategory));
        }
        public async Task <IActionResult> Post(GoodsCategory formData)
        {
            // 图片文件保存
            formData.SaveImgUrl = FileSave(formData.ImgFile);
            // 创建日期
            formData.CreateDate = DateTime.Now;
            // 更新日期
            formData.ModifyDate = DateTime.Now;
            //GoodsCategory seveData = Extensions.Func.ObjToObj<GoodsCategory, GoodsCategory>(formData);
            _goodsCategory.Insert(formData);
            IEnumerable <GoodsCategory> data = await _goodsCategory.GetAll();

            return(Json(data));
        }