/// <summary>
 /// 添加或更新关卡进度
 /// </summary>
 /// <param name="process">进度</param>
 /// <param name="code">识别码</param>
 public Assets.Status AddOrUpdateLevelProcess(LevelProcess process, string code)
 {
     if (Assets.CheckLevelProcess(process, code))
     {
         var pro = _context.LevelProcesses.FirstOrDefault(p => string.Equals(p.Token, process.Token));
         if (pro != null)
         {
             if (pro.LevelID + 1 == process.LevelID)
             {
                 pro.LevelID       = process.LevelID;
                 pro.LevelName     = process.LevelName;
                 pro.IP            = process.IP;
                 pro.UpdateTimeUTC = process.UpdateTimeUTC;
                 _context.SaveChanges();
             }
             else if (pro.LevelID >= process.LevelID)
             {
                 pro.IP            = process.IP;
                 pro.UpdateTimeUTC = process.UpdateTimeUTC;
                 _context.SaveChanges();
             }
             else
             {
                 return(Assets.Status.NotFound);
             }
             return(Assets.Status.Success);
         }
         else if (process.LevelID == 0)
         {
             _context.Add(process);
             _context.SaveChanges();
             return(Assets.Status.Success);
         }
         else
         {
             return(Assets.Status.NotFound);
         }
     }
     return(Assets.Status.Fail);
 }
예제 #2
0
 /// <summary>
 /// 检验识别码与关卡是否匹配
 /// </summary>
 /// <param name="process">进度信息</param>
 /// <param name="code">识别码</param>
 public static bool CheckLevelProcess(LevelProcess process, string code) =>
 !string.IsNullOrWhiteSpace(process.Token) &&
 !string.IsNullOrWhiteSpace(process.LevelName) &&
 !string.IsNullOrWhiteSpace(process.IP) &&
 LevelCode.ContainsKey(process.LevelName) &&
 string.Equals(LevelCode[process.LevelName], code);