Exemple #1
0
        // 删除
        public IActionResult DeleteGoodsClassification(int?code)
        {
            var Aid = HttpContext.Session.GetString("Aid");

            if (Aid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            if (code == null)
            {
                return(Content("500"));
            }
            var GoodsInfo = _context.GoodsInfo
                            .FirstOrDefault(m => m.GoodsClassificationCode == code);

            if (GoodsInfo != null)
            {
                return(Content("404"));
            }
            GoodsClassification goodsClassification = _context.GoodsClassification.FirstOrDefault(u => u.GoodsClassificationCode == code);

            _context.GoodsClassification.Remove(goodsClassification);
            _context.SaveChanges();
            return(Content("200"));
        }
Exemple #2
0
        //添加动作
        public async Task <IActionResult> GoodsClassificationCreates(int?GoodsCommoditiesCode, string GoodsClassificationName, string GoodsClassificationImageUrl)
        {
            var Aid = HttpContext.Session.GetString("Aid");

            if (Aid == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            if (GoodsCommoditiesCode == null || GoodsClassificationName == null)
            {
                return(Content("404"));
            }
            if (_context.GoodsClassification.Where(a => a.GoodsClassificationName == GoodsClassificationName).Count() == 0)
            {
                try
                {
                    var GoodsClassification = new GoodsClassification
                    {
                        GoodsClassificationName     = GoodsClassificationName,
                        GoodsClassificationImageUrl = GoodsClassificationImageUrl,
                        GoodsCommoditiesCode        = Convert.ToInt32(GoodsCommoditiesCode),
                    };
                    _context.Add(GoodsClassification);
                    await _context.SaveChangesAsync();

                    return(Content("200"));
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Content("500"));
                }
            }
            else
            {
                return(Content("201"));
            }
        }