コード例 #1
0
 public static void AddShop(Shop shop)
 {
     using (AladingWebEntities context = ContextProvider.DataContext(ConnectionHelper.ConnectionString))
     {
         var user = context.User.FirstOrDefault(c => c.UserCode == shop.UserCode);
         if (user == null)
         {
             throw new ServiceException("用户不存在!");
         }
         if (user.HasShop > user.MaxShop)
         {
             throw new ServiceException("已有店铺数量不大于允许的最大店铺数量!");
         }
         user.HasShop++;
         context.AddToShop(shop);
         context.SaveChanges();
     }
 }