Example #1
0
        public async Task <IActionResult> UploadCompanyPhoto([FromBody] ResourceUploadViewModel model)
        {
            Company company = DataContext.Company;
            var     result  = await ResourceManager.UploadPhoto(new FileUploadContext()
            {
                FileName = model.File.FileName,
                Folder   = "Company",
                Stream   = model.File.OpenReadStream()
            });

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            Photo photo = result.Entity;

            photo._Reference = company.Id;
            company.Resources.Add(photo);

            if (company._Logo == Guid.Empty)
            {
                company._Logo = photo.Id;
            }

            await DataContext.Store.UpdateOneAsync(company);

            return(Created(photo.Url, null));
        }
Example #2
0
        public IActionResult Upload()
        {
            ResourceUploadViewModel viewModel = new ResourceUploadViewModel();

            viewModel.UploadStage = UploadStage.Upload;
            return(View(viewModel));
        }
Example #3
0
        public async Task<IActionResult> UploadPlatformPhoto([FromBody]ResourceUploadViewModel model)
        {
            Platform platform = await DataContext.Store.GetOneAsync<Platform>(p => p.Id == model.ReferenceId);

            if (platform == null) return NotFound("No platform exists with the given Id");

            var result = await ResourceManager.UploadPhoto(new FileUploadContext()
            {
                FileName = model.File.FileName,
                Folder = @"Company\Platforms",
                Stream = model.File.OpenReadStream()
            });

            if (!result.Success) return BadRequest(result.Message);

            Photo photo = result.Entity;
            photo._Reference = platform.Id;
            platform.Resources.Add(photo);

            if (platform._DisplayPicture == Guid.Empty) platform._DisplayPicture = photo.Id;

            await DataContext.Store.UpdateOneAsync(platform);

            return Created(photo.Url, null);
        }
Example #4
0
        public ActionResult doUpload(ResourceUploadViewModel model, HttpPostedFileBase file, HttpPostedFileBase file1)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    Entity.User user     = CurrentUser;
                    var         fileName = Path.Combine(Request.MapPath("~/Upload"), DateHelper.GetTimeStamp() + Path.GetFileName(file.FileName));
                    try
                    {
                        file.SaveAs(fileName);
                        Resource resource = new Resource {
                            ResourceName = model.ResourceName, Description = model.Description, TypeAsInt = model.ResourceType, UploadTime = DateTime.Now, Path = DateHelper.GetTimeStamp() + Path.GetFileName(file.FileName), UserId = user.ID
                        };

                        if (file1 != null)
                        {
                            System.IO.Stream stream = file1.InputStream;
                            byte[]           buffer = new byte[stream.Length];
                            stream.Read(buffer, 0, (int)stream.Length);
                            stream.Close();
                            resource.Icon = buffer;


                            db.Resources.Add(resource);
                            db.SaveChanges();
                            ResourceViewModel vResource = new ResourceViewModel(resource);

                            var context = GlobalHost.ConnectionManager.GetHubContext <ResourceHub>(); //得到Signalr context
                            context.Clients.All.GetNew(vResource);                                    //将新上传的资源广播到全部客户端
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "上传资源截图!");
                        }
                    }
                    catch
                    {
                        ModelState.AddModelError("", "上传文件出错");
                    }
                }

                else
                {
                    ModelState.AddModelError("", "上传文件出错");
                }
            }
            else
            {
                ModelState.AddModelError("", "上传文件出错");
            }
            return(View(model));
        }
Example #5
0
        public async Task <IActionResult> Upload(ResourceUploadViewModel viewModel)
        {
            if (viewModel.File?.Length > 0)
            {
                await _channel.SetAsync(viewModel.File);

                viewModel.File        = null;
                viewModel.UploadStage = UploadStage.Comleted;
            }

            return(View(viewModel));
        }