Exemplo n.º 1
0
 public IActionResult Add(string PathID, int DocumentType, string DocumentID)
 {
     ViewBag.DocumentType = DocumentType;
     ViewBag.PathID       = PathID;
     Models.TMT_Documents Model = null;
     if (!string.IsNullOrWhiteSpace(DocumentID))
     {
         Model = DB.TMT_Documents.Find(DocumentID);
         if (Model.CreateUserID != G.User.UserID)
         {
             return(Json("无权编辑此文档,必须是文档的创建者!"));
         }
     }
     return(View(Model));
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Add(Models.TMT_Documents Model)
        {
            if (!string.IsNullOrWhiteSpace(Model.DocumentID))
            {
                var TempModel = DB.TMT_Documents.Find(Model.DocumentID);
                if (TempModel.CreateUserID != G.User.UserID)
                {
                    return(Json("无权编辑此文档,必须是文档的创建者!"));
                }
            }
            switch (Model.DocumentType)
            {
            case 0:
                if (string.IsNullOrWhiteSpace(Model.DocumentName))
                {
                    return(Json("[文件夹名称]不可为空!"));
                }
                if (!string.IsNullOrWhiteSpace(Model.DocumentID))
                {
                    if (DB.TMT_Documents.Any(c => c.DocumentName == Model.DocumentName && c.DocumentType == Model.DocumentType && c.PathID == Model.PathID && c.DocumentID != Model.DocumentID))
                    {
                        return(Json($"[{Model.DocumentName}]已经存在!"));
                    }
                    var Temp = DB.TMT_Documents.Find(Model.DocumentID);
                    Temp.DocumentName = Model.DocumentName;
                    Temp.IsPublic     = Model.IsPublic;
                }
                else
                {
                    if (DB.TMT_Documents.Any(c => c.DocumentName == Model.DocumentName && c.DocumentType == Model.DocumentType && c.PathID == Model.PathID))
                    {
                        return(Json($"[{Model.DocumentName}]已经存在!"));
                    }
                    Model.DocumentID   = Guid.NewGuid().ToString("N");
                    Model.Class        = GetIcon(Model.DocumentType, Model.DocumentName);
                    Model.CreateUserID = G.User.UserID;
                    DB.TMT_Documents.Add(Model);
                }
                DB.SaveChanges();
                break;

            case 1:
                if (string.IsNullOrWhiteSpace(Model.DocumentName))
                {
                    return(Json("[文档名称]不可为空!"));
                }
                if (!string.IsNullOrWhiteSpace(Model.DocumentID))
                {
                    if (DB.TMT_Documents.Any(c => c.DocumentName == Model.DocumentName && c.DocumentType == Model.DocumentType && c.PathID == Model.PathID && c.DocumentID != Model.DocumentID))
                    {
                        return(Json($"[{Model.DocumentName}]已经存在!"));
                    }
                    var Temp = DB.TMT_Documents.Find(Model.DocumentID);
                    Temp.DocumentName = Model.DocumentName;
                    Temp.IsPublic     = Model.IsPublic;
                    Temp.IsShare      = Model.IsShare;
                }
                else
                {
                    if (DB.TMT_Documents.Any(c => c.DocumentName == Model.DocumentName && c.DocumentType == Model.DocumentType && c.PathID == Model.PathID))
                    {
                        return(Json($"[{Model.DocumentName}]已经存在!"));
                    }
                    Model.DocumentID   = Guid.NewGuid().ToString("N");
                    Model.Class        = GetIcon(Model.DocumentType, Model.DocumentName);
                    Model.Content      = "";
                    Model.CreateUserID = G.User.UserID;
                    Model.IsPublic     = Model.IsPublic;
                    Model.IsShare      = Model.IsShare;
                    DB.TMT_Documents.Add(Model);
                }
                DB.SaveChanges();
                break;

            case 2:
                if (string.IsNullOrWhiteSpace(Model.DocumentName))
                {
                    return(Json("[附件名称]不可为空!"));
                }
                if (!string.IsNullOrWhiteSpace(Model.DocumentID))
                {
                    if (DB.TMT_Documents.Any(c => c.DocumentName == Model.DocumentName && c.DocumentType == Model.DocumentType && c.PathID == Model.PathID && c.DocumentID != Model.DocumentID))
                    {
                        return(Json($"[{Model.DocumentName}]已经存在!"));
                    }
                    var Temp = DB.TMT_Documents.Find(Model.DocumentID);
                    Temp.DocumentName = Model.DocumentName;
                    Temp.IsPublic     = Model.IsPublic;
                    if (HttpContext.Request.Form.Files.Count > 0)
                    {
                        var ReFiles = await Command.Helper.SaveAsync(HttpContext.Request.Form.Files);

                        Temp.Content = ReFiles.path;
                        Temp.Class   = GetIcon(Model.DocumentType, Model.DocumentName);
                    }
                    Temp.IsShare = Model.IsShare;
                }
                else
                {
                    if (DB.TMT_Documents.Any(c => c.DocumentName == Model.DocumentName && c.DocumentType == Model.DocumentType && c.PathID == Model.PathID))
                    {
                        return(Json($"[{Model.DocumentName}]已经存在!"));
                    }
                    if (HttpContext.Request.Form.Files.Count < 1)
                    {
                        return(Json($"未检测到上传的附件!"));
                    }
                    var ReFiles = await Command.Helper.SaveAsync(HttpContext.Request.Form.Files);

                    Model.DocumentID   = Guid.NewGuid().ToString("N");
                    Model.Class        = GetIcon(Model.DocumentType, Model.DocumentName);
                    Model.Content      = ReFiles.path;
                    Model.CreateUserID = G.User.UserID;
                    DB.TMT_Documents.Add(Model);
                }
                DB.SaveChanges();
                break;

            case 3:
                if (string.IsNullOrWhiteSpace(Model.DocumentName))
                {
                    return(Json("[链接名称]不可为空!"));
                }
                if (string.IsNullOrWhiteSpace(Model.Content))
                {
                    return(Json("[链接Url]不可为空!"));
                }
                if (!string.IsNullOrWhiteSpace(Model.DocumentID))
                {
                    if (DB.TMT_Documents.Any(c => c.DocumentName == Model.DocumentName && c.DocumentType == Model.DocumentType && c.PathID == Model.PathID && c.DocumentID != Model.DocumentID))
                    {
                        return(Json($"[{Model.DocumentName}]已经存在!"));
                    }
                    var Temp = DB.TMT_Documents.Find(Model.DocumentID);
                    Temp.DocumentName = Model.DocumentName;
                    Temp.IsPublic     = Model.IsPublic;
                    Temp.Content      = Model.Content;
                }
                else
                {
                    if (DB.TMT_Documents.Any(c => c.DocumentName == Model.DocumentName && c.DocumentType == Model.DocumentType && c.PathID == Model.PathID))
                    {
                        return(Json($"[{Model.DocumentName}]已经存在!"));
                    }
                    Model.DocumentID   = Guid.NewGuid().ToString("N");
                    Model.Class        = GetIcon(Model.DocumentType, Model.DocumentName);
                    Model.CreateUserID = G.User.UserID;
                    DB.TMT_Documents.Add(Model);
                }
                DB.SaveChanges();
                break;
            }
            return(Json(new { Model.DocumentType, Model.DocumentID }));
        }