当前位置: 首页>>代码示例>>C#>>正文


C# IFormFile.ReadAllBytesAsync方法代码示例

本文整理汇总了C#中IFormFile.ReadAllBytesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IFormFile.ReadAllBytesAsync方法的具体用法?C# IFormFile.ReadAllBytesAsync怎么用?C# IFormFile.ReadAllBytesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFormFile的用法示例。


在下文中一共展示了IFormFile.ReadAllBytesAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EditAvatar

 public async Task<IActionResult> EditAvatar(long id,IFormFile avatar,User Model)
 {
     var user = DB.Users
         .Include(x=>x.Avatar)
         .Where(x => x.Id == id)
         .SingleOrDefault();
     if (avatar != null)
     {
         try
         {
             DB.Files.Remove(DB.Files.Single(x => x.Id == user.AvatarId));
         }
         catch { }
         var file = new CodeComb.AspNet.Upload.Models.File
         {
             Bytes = await avatar.ReadAllBytesAsync(),
             ContentLength = avatar.Length,
             ContentType = avatar.ContentType,
             FileName = avatar.GetFileName(),
             Time = DateTime.Now
         };
         DB.Files.Add(file);
         user.AvatarId = file.Id;
     }
     DB.SaveChanges();
     return RedirectToAction("Center", "Home");
 }
开发者ID:Cream2015,项目名称:EMWeb,代码行数:27,代码来源:HomeController.cs

示例2: Edit

        public async Task<IActionResult> Edit(long id, IFormFile TestArchive, IFormFile AnswerArchive, Experiment Model, bool IsChecked)
        {
            var exp = DB.Experiments
               .Where(x => x.Id == id)
               .SingleOrDefault();

            if (exp == null)
                return Prompt(x =>
                {
                    x.Title = "资源没有找到";
                    x.Details = "您请求的资源没有找到,请返回重试!";
                    x.StatusCode = 404;
                });

            exp.Title = Model.Title;
            exp.Namespace = Model.Namespace;
            exp.NuGet = Model.NuGet;
            exp.OS = Model.OS;
            exp.CheckPassed = IsChecked;
            exp.TimeLimit = Model.TimeLimit;
            if (TestArchive != null)
                exp.TestArchive = await TestArchive.ReadAllBytesAsync();
            if (AnswerArchive != null)
                exp.AnswerArchive = await AnswerArchive.ReadAllBytesAsync();
            exp.Difficulty = Model.Difficulty;
            exp.Version = Model.Version;
            DB.SaveChanges();
            return Prompt(x =>
            {
                x.Title = "修改成功";
                x.Details = "该实验已保存成功!";
            });
        }
开发者ID:Jeffiy,项目名称:vnextcn.org,代码行数:33,代码来源:ExperimentController.cs

示例3: Submit

        public async Task<IActionResult> Submit(long id, IFormFile file, string nuget)
        {
            var exp = DB.Experiments
                .Where(x => x.Id == id)
                .SingleOrDefault();
            if (exp == null)
                return Prompt(x => 
                {
                    x.Title = "资源没有找到";
                    x.Details = "您请求的资源没有找到,请返回重试!";
                    x.StatusCode = 404;
                });
            if (!User.AnyRoles("Root, Master") && exp.CheckPassed == false)
                return Prompt(x => 
                {
                    x.Title = "资源没有找到";
                    x.Details = "您请求的资源没有找到,请返回重试!";
                    x.StatusCode = 404;
                });
            if (!User.AnyRoles("Root, Master") && exp.Contests.Count > 0 && exp.Contests.Max(y => y.Contest.End) > DateTime.Now)
                return Prompt(x =>
                {
                    x.Title = "资源没有找到";
                    x.Details = "您请求的资源没有找到,请返回重试!";
                    x.StatusCode = 404;
                });
            var Status = new Status
            {
                UserId = User.Current.Id,
                Time = DateTime.Now,
                Result = StatusResult.Queued,
                ExperimentId = id,
                Archive = await file.ReadAllBytesAsync(),
                MemoryUsage = file.Length / 1024
            };

            switch(exp.OS)
            {
                case OSType.CrossPlatform:
                    Status.RunWithLinux = true;
                    Status.RunWithOsx = true;
                    Status.RunWithWindows = true;
                    Status.LinuxResult = StatusResult.Queued;
                    Status.OsxResult = StatusResult.Queued;
                    Status.WindowsResult = StatusResult.Queued;
                    break;
                case OSType.Random:
                    switch (NodeProvider.GetFreeNode().OS)
                    {
                        case Package.OSType.Linux:
                            Status.RunWithLinux = true;
                            Status.LinuxResult = StatusResult.Queued;
                            break;
                        case Package.OSType.OSX:
                            Status.RunWithOsx = true;
                            Status.OsxResult = StatusResult.Queued;
                            break;
                        case Package.OSType.Windows:
                            Status.RunWithWindows = true;
                            Status.WindowsResult = StatusResult.Queued;
                            break;
                    }
                    break;
                case OSType.Linux:
                    Status.RunWithLinux = true;
                    Status.LinuxResult = StatusResult.Queued;
                    break;
                case OSType.OSX:
                    Status.RunWithOsx = true;
                    Status.OsxResult = StatusResult.Queued;
                    break;
                case OSType.Windows:
                    Status.RunWithWindows = true;
                    Status.WindowsResult = StatusResult.Queued;
                    break;
            }

            DB.Statuses.Add(Status);
            DB.SaveChanges();

            if (Status.RunWithLinux)
            {
                var node = NodeProvider.GetFreeNode(Package.OSType.Linux);
                if (node == null)
                    Status.LinuxResult = Models.StatusResult.Ignored;
                else
                    await node.SendJudgeTask(Status.Id, Status.Archive, Status.Experiment.TestArchive, Status.NuGet + "\r\n" + Status.Experiment.NuGet);
            }
            if (Status.RunWithWindows)
            {
                var node = NodeProvider.GetFreeNode(Package.OSType.Windows);
                if (node == null)
                    Status.WindowsResult = Models.StatusResult.Ignored;
                else
                    await node.SendJudgeTask(Status.Id, Status.Archive, Status.Experiment.TestArchive, Status.NuGet + "\r\n" + Status.Experiment.NuGet);
            }
            if (Status.RunWithOsx)
            {
                var node = NodeProvider.GetFreeNode(Package.OSType.OSX);
                if (node == null)
//.........这里部分代码省略.........
开发者ID:Jeffiy,项目名称:vnextcn.org,代码行数:101,代码来源:ExperimentController.cs

示例4: Edit

 public async Task<IActionResult> Edit(long id, IFormFile avatar, User Model)
 {
     var user = DB.Users.Where(x => x.Id == id).SingleOrDefault();
     if (user == null)
         return Prompt(x =>
         {
             x.Title = "资源没有找到";
             x.Details = "您请求的资源没有找到,请返回重试!";
             x.StatusCode = 404;
         });
     var roles = await UserManager.GetRolesAsync(user);
     if (roles.Contains("Root") && !User.IsInRole("Root"))
         return Prompt(x =>
         {
             x.Title = "没有权限";
             x.Details = "您的权限不足以编辑该用户,请使用更高权限帐号执行本操作。";
             x.StatusCode = 403;
         });
     if (User.Current.Id != id && !User.AnyRoles("Root, Master"))
         return Prompt(x =>
         {
             x.Title = "没有权限";
             x.Details = "您的权限不足以编辑该用户,请使用更高权限帐号执行本操作。";
             x.StatusCode = 403;
         });
     if (avatar != null)
     {
         user.Avatar = await avatar.ReadAllBytesAsync();
         user.AvatarContentType = avatar.ContentType;
     }
     user.Motto = Model.Motto;
     user.WebSite = Model.WebSite;
     user.Organization = Model.Organization;
     DB.SaveChanges();
     return Prompt(x =>
     {
         x.Title = "修改成功";
         x.Details = "用户资料已经保存成功!";
     });
 }
开发者ID:Jeffiy,项目名称:vnextcn.org,代码行数:40,代码来源:AccountController.cs


注:本文中的IFormFile.ReadAllBytesAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。