Преглед изворни кода

添加错误提示,待完成

DuGuYang пре 3 година
родитељ
комит
8e0e57e9d0
1 измењених фајлова са 44 додато и 9 уклоњено
  1. 44 9
      Areas/Admin/Controllers/MainServer/SchoolMakerStudyController.cs

+ 44 - 9
Areas/Admin/Controllers/MainServer/SchoolMakerStudyController.cs

@@ -290,6 +290,7 @@ namespace MySystem.Areas.Admin.Controllers
         {
             ExcelData = HttpUtility.UrlDecode(ExcelData);
             JsonData list = JsonMapper.ToObject(ExcelData);
+            var error = "";
             for (int i = 1; i < list.Count; i++)
             {
                 JsonData dr = list[i];
@@ -298,24 +299,42 @@ namespace MySystem.Areas.Admin.Controllers
                 string[] Auth = Auths.Split(',');
                 var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
                 var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
+                if (userInfo.Id == 0)
+                {
+                    error += "创客" + MakerCode + "不存在" + '\n';
+                }
+                if (!string.IsNullOrEmpty(error))
+                {
+                    return "Warning|" + error;
+                }
                 var check = db.UserCardRecord.Any(m => m.Id == userInfo.Id);
                 if (check)
                 {
                     var auth = db.UserCardRecord.FirstOrDefault(m => m.Id == userInfo.Id) ?? new UserCardRecord();
-                    auth.SeoDescription = auth.SeoDescription.TrimEnd(',');
+                    // auth.SeoDescription = auth.SeoDescription.TrimEnd(',');
                     var time = 0;
                     foreach (var item in Auth)
                     {
-                        time += 1;
-                        if (!auth.SeoDescription.Contains(item))
+                        var col = bsdb.Col.FirstOrDefault(m => m.ColId == item) ?? new BsModels.Col();
+                        if (col.Id == 0)
                         {
-                            if (time == 1)
-                            {
-                                auth.SeoDescription += "," + item + ",";
-                            }
-                            else
+                            error += "权限编号" + item + "不存在" + '\n';
+                        }
+                        else
+                        {
+                            time += 1;
+                            if (!auth.SeoDescription.Contains("," + item + ","))
                             {
+                                // if (time == 1)
+                                // {
+                                //     auth.SeoDescription += "," + item + ",";
+                                // }
+                                // else
+                                // {
+                                //     auth.SeoDescription += item + ",";
+                                // }
                                 auth.SeoDescription += item + ",";
+
                             }
                         }
                     }
@@ -325,12 +344,28 @@ namespace MySystem.Areas.Admin.Controllers
                 }
                 else
                 {
+                    foreach (var item in Auth)
+                    {
+                        var col = bsdb.Col.FirstOrDefault(m => m.ColId == item) ?? new BsModels.Col();
+                        if (col.Id == 0)
+                        {
+                            error += "权限编号" + item + "不存在" + '\n';
+                        }
+                        else
+                        {
+                            Auths += "," + item + ",";
+                        }
+                    }
+                    if (!string.IsNullOrEmpty(error))
+                    {
+                        return "Warning|" + error;
+                    }
                     var query = db.UserCardRecord.Add(new UserCardRecord()
                     {
                         Id = userInfo.Id,
                         CreateDate = DateTime.Now, //创建时间
                         CreateMan = SysUserName + "-" + SysRealName,
-                        SeoDescription = Auths,
+                        SeoDescription = "," + Auths + ",",
                     }).Entity;
                     db.SaveChanges();
                 }