Beispiel #1
0
    protected void btnSave_Click(object sender, System.EventArgs e)
    {
        string str   = "";
        string value = this.hfldFolderName.Value;
        int    count = FileService.GetListArray(string.Concat(new string[]
        {
            " where FileName='",
            value,
            "' and FileType!=0 and ParentId='",
            this.tvFile.SelectedValue,
            "'  and IsValid=0"
        })).Count;

        if (this.hdType.Value == "add")
        {
            if (count > 0)
            {
                base.RegisterScript("alert('系统提示:\\n\\n 添加失败,此目录名称已存在!');");
                return;
            }
            FileModel FileModel = new FileModel();
            FileModel.CreateTime  = new System.DateTime?(System.DateTime.Now);
            FileModel.FileName    = value;
            FileModel.FileOwner   = base.UserCode;
            FileModel.FileSize    = "";
            FileModel.FileNewName = "";
            FileModel.FileType    = "2";
            FileModel.IsValid     = 0;
            FileModel.Id          = this.hdGuid.Value;
            FileModel.UserCodes   = this.hdUserCodes.Value;
            FileModel.ParentId    = ((this.tvFile.SelectedValue == "") ? this.hdGuid.Value : this.tvFile.SelectedValue);
            str = FileModel.ParentId;
            FileService.Add(FileModel);
        }
        else
        {
            FileModel model = FileService.GetModel(this.hfldPurchaseChecked.Value);
            if (model != null)
            {
                if (count > 0 && model.FileName != value)
                {
                    base.RegisterScript("alert('系统提示:\\n\\n 编辑失败,此目录名称已存在!');");
                    return;
                }
                model.FileName = value;
                str            = model.ParentId;
                FileService.Update(model);
            }
        }
        base.RegisterScript("location='MenuList.aspx?id=" + str + "'");
    }
        public void FileShouldBeAddedSuccessfully()
        {
            var stream = GenerateStream();
            var id     = _service.Add(stream);

            Assert.AreNotEqual(null, id);
            Assert.AreNotEqual(string.Empty, id);
        }
Beispiel #3
0
 public IActionResult Create(string title, string description, IFormFile file)
 {
     // do other validations on  model as needed
     try {
         if (file != null)
         {
             // create unique file name
             var uniqueFileName = GetUniqueFileName(file.FileName);
             // path to uploaded files folder
             var uploads = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot/files");
             // the file path
             var filePath = System.IO.Path.Combine(uploads, uniqueFileName);
             // copy the file from memory to that folder
             using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
                 file.CopyTo(fileStream);
             //file.CopyTo(new System.IO.FileStream(filePath, System.IO.FileMode.Create));
             //Save model to db table
             _fileService.Add(title, description, "files/" + uniqueFileName);
             // log user action
             if (_userManager.IsSignedIn(User))
             {
                 _logger.Add(
                     User.Identity.Name,
                     Request.HttpContext.Connection.RemoteIpAddress.ToString(),
                     "Add new file (title: " + title + ")"
                     );
             }
             else
             {
                 _logger.Add(
                     "",
                     Request.HttpContext.Connection.RemoteIpAddress.ToString(),
                     "Add new file (title: " + title + ")"
                     );
             }
         }
     }
     catch (Exception) {
         // just pass new createfile object to view file (Create.cshtml)
         return(View());
     }
     // just pass new createfile object to view file (Create.cshtml)
     return(View());
 }
Beispiel #4
0
        public ActionResult Index()
        {
            var datetimeTW = DateTime.UtcNow.AddHours(8);

            _fileService.Add(new FileInfo()
            {
                KindID        = 123,
                Category      = "123",
                Title         = "123",
                FileUrl       = "1234",
                CreateAccount = "dadsad",
                ModifyAccount = "fdsfsdfs",
                StratDateTime = datetimeTW,
                EndDateTime   = datetimeTW.AddHours(8),
                Status        = 1,
            });


            return(View());
        }