예제 #1
0
        public ActionResult Evidence(string id, Evidence evidence)
        {
            if (WasClicked(BsgButtons.UploadFile))
            {
                if (Request.Files.Count == 0)
                {
                    ModelState.AddModelError("", "Could not upload file");
                    return(Evidence_Render(id, evidence));
                }

                var file = Request.Files[0];

                if (string.IsNullOrWhiteSpace(file.FileName))
                {
                    ModelState.AddModelError("", "Please select a file to upload");
                    return(Evidence_Render(id, evidence));
                }

                const int maxSize = 1024 * 1024 * 2;

                if (file.ContentLength > maxSize)
                {
                    ModelState.AddModelError("", "Please select a file that is smaller than 2MB");
                    return(Evidence_Render(id, evidence));
                }

                using (var br = new BinaryReader(file.InputStream))
                {
                    var addFile = new AddEvidenceFile
                    {
                        FormId   = id,
                        Filename = file.FileName,
                        Content  = br.ReadBytes((int)file.InputStream.Length),
                    };

                    return(Exec(addFile,
                                success: () => Redirect(BsgActions.Evidence(id)),
                                failure: () => Evidence_Render(id, evidence)));
                }
            }
            else if (WasClicked(BsgButtons.RemoveFile))
            {
                var cloudName = Request.Form[BsgButtons.RemoveFile];

                var delFile = new RemoveEvidenceFile
                {
                    FormId    = id,
                    CloudName = cloudName,
                };

                return(Exec(delFile,
                            success: () => Redirect(BsgActions.Evidence(id)),
                            failure: () => Evidence_Render(id, evidence)));
            }

            var cmd = new AddEvidence
            {
                FormId   = id,
                Evidence = evidence,
            };

            return(Exec(cmd,
                        success: next => RedirectNext(next),
                        failure: () => Evidence_Render(id, evidence)));
        }
 public override string Action(string formId)
 {
     return(BsgActions.Evidence(formId));
 }