Exemple #1
0
        public async Task <APIResult> AddMemberLevel([FromBody] AddMemberLevelModel input)
        {
            var shopMemberLevel = db.ShopMemberLevel.Where(m => !m.IsDel && m.ShopId.Equals(input.ShopId));

            if (shopMemberLevel.Count() != 0)
            {
                var maxlevel = await shopMemberLevel.OrderByDescending(m => m.Sort).FirstOrDefaultAsync();

                if (input.MinIntegral - maxlevel.MaxIntegral != 1)
                {
                    return(await Task.FromResult(Error($"最低积分必须比上一个会员等级的最高积分加一,最低积分必须为 { maxlevel.MaxIntegral + 1}")));
                }

                input.Sort = maxlevel.Sort + 1;
                var addShopMemberLevel = _mapper.Map <ShopMemberLevel>(input);
                await db.ShopMemberLevel.AddAsync(addShopMemberLevel);
            }
            else
            {
                input.Sort = 1;
                var addShopMemberLevel = _mapper.Map <ShopMemberLevel>(input);
                await db.ShopMemberLevel.AddAsync(addShopMemberLevel);
            }
            await db.SaveChangesAsync();

            await ShopMemberLevelServer.UpdateAllMemberLevel(db, db.ShopMemberSet.FirstOrDefault(m => !m.IsDel && m.ShopId.Equals(input.ShopId)), input.ShopId, _logger);

            SetSort(input.ShopId);
            return(await Task.FromResult(Success()));
        }
Exemple #2
0
        public async Task <APIResult> DelMemberLevel([FromBody] AddMemberLevelModel input)
        {
            var shopMemberLevels = db.ShopMemberLevel.Find(input.Id);

            if (shopMemberLevels == null || shopMemberLevels.IsDel)
            {
                return(await Task.FromResult(Error("记录不存在")));
            }

            var minLevel = await db.ShopMemberLevel.Where(m => m.Shop.Equals(input.ShopId) && !m.IsDel).OrderByDescending(m => m.Sort).FirstOrDefaultAsync();

            if (minLevel.Id != input.Id)
            {
                return(await Task.FromResult(Error("需要从等级最低的开始删除")));
            }
            minLevel.IsDel = true;
            await db.SaveChangesAsync();

            await ShopMemberLevelServer.UpdateAllMemberLevel(db, db.ShopMemberSet.FirstOrDefault(m => !m.IsDel && m.ShopId.Equals(input.ShopId)), input.ShopId, _logger);

            return(await Task.FromResult(Success("删除成功")));
        }