public ActionResult Insert(string lastUpload)
        {
            var uploadModel = new UploadModel();
            TryUpdateModel(uploadModel);
            var constituentId =  Convert.ToInt32(Session["loggedInConstituentId"]);
            uploadModel.Constituent = new Constituent { Id = constituentId };

            mapper = new AutoDataContractMapper();
            var uploadData = new UploadData();
            mapper.Map(uploadModel, uploadData);

            HttpHelper.Post(string.Format(serviceBaseUri + "/UploadFiles"), uploadData);

            return View(new GridModel(Model));
        }
示例#2
0
        public ActionResult Upload(UploadModel model)
        {
            try
            {
                using (var db = new BusinessLogic.Data.SharingDataContext())
                {
                    var shareToken = ShareToken.Parse(model.ShareToken);
                    var shareTokenBytes = shareToken.GetBytes();

                    var sharedSet = db.SharedFileSets
                        .Where(x => x.ShareToken == shareTokenBytes && x.ExpirationDateTime > DateTime.UtcNow && x.AllowUpload)
                        .Include(i=>i.FileSet)
                        .SingleOrDefault();

                    if (sharedSet == null || !ValidatePasswordCookie(sharedSet.Password) || !sharedSet.AllowUpload)
                    {
                        return new HttpStatusCodeResult(403);
                    }

                    string storagePath;
                    foreach (var fileKey in this.Request.Files.AllKeys)
                    {
                        storagePath = this.FileStorageService.Put(this.Request.Files[fileKey].InputStream);

                        db.StoredFiles.Add(new BusinessLogic.Data.StoredFile()
                        {
                            FileSet = sharedSet.FileSet,
                            ContentType = this.Request.Files[fileKey].ContentType,
                            Length = this.Request.Files[fileKey].ContentLength,
                            Filename = System.IO.Path.GetFileName(this.Request.Files[fileKey].FileName),
                            OwnerUsername = this.User.Identity.Name,
                            StoragePath = storagePath,
                            CreateUsername = this.User.Identity.Name,
                            CreateDateTime = DateTime.UtcNow
                        });
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Response.ContentType = "text/plain";
                Response.Write(ex.Message);
                return new HttpStatusCodeResult(500);
            }

            if (Request.IsAjaxRequest() || Request.Form["IsFlashRequest"] == "1")
            {
                Response.ContentType = "text/plain";
                Response.Write("OK");
                return new HttpStatusCodeResult(200);
            }
            else
            {
                return RedirectToAction("Index", new { id = model.ShareToken });
            }
        }