public ActionResult Index()
 {
     var model = new FileUploadViewModel();
     ViewBag.Hidden = "display: none";
     ViewBag.UserName = "";
     ViewBag.ImageNumber = "";
     return View(model);
 }
 public ActionResult Index()
 {
     var model = new FileUploadViewModel();
     ViewBag.Title = "Upload Page";
     ViewBag.Link = "";
     ViewBag.Hidden = "display: none";
     return View(model);
 }
        public ActionResult FileUpload(HttpPostedFileBase file, int radio, bool whiteSignatureBackground)
        {
            Debug.Print("checkbox: " + whiteSignatureBackground.ToString());
            var model = new FileUploadViewModel();
            if (file != null)
            {
                var fileContentType = file.ContentType;
                if (!fileContentType.Contains("image"))
                {
                    model.errorMessage = "You must select a jpeg or png file to upload";
                    ViewBag.Title = "Upload Page";
                    ViewBag.Link = "";
                    ViewBag.Hidden = "display: none";
                    return View("Index", model);
                }

                string imageName = Path.GetFileName(file.FileName);
                using (MemoryStream ms = new MemoryStream())
                {
                    file.InputStream.CopyTo(ms);
                    byte[] fileArray = ms.GetBuffer();
                    ms.Close();
                    int currentUserId;
                    FileUploadResponse fileUploadResponse = new FileUploadResponse() { Status = ResultStatus.Error } ;
                    if (int.TryParse(Request.LogonUserIdentity.GetUserId(), out currentUserId))
                        fileUploadResponse = _fps.FileUpload(currentUserId, fileArray, imageName, radio, !whiteSignatureBackground);

                    if (fileUploadResponse.Status == ResultStatus.Error)
                    {
                        //do error handling here 
                    }
                    else
                    {
                        var imageData = _fps.GetImageById(fileUploadResponse.SignedImageId).ImageBinary;
                        return File(imageData, "image/png");
                    }
                }
            }

            model = new FileUploadViewModel();
            model.errorMessage = "You must select a jpeg or png file to upload";
            ViewBag.Title = "Upload Page";
            ViewBag.Link = "";
            ViewBag.Hidden = "display: none";
            return View("Index", model);
        }
        /// <summary>
        /// reads in image file and runs DetectSignature on that file
        /// </summary>
        /// <param name="file"></param>
        /// <returns>page displaying who uploaded file belongs to</returns>
        public ActionResult DetectMark(HttpPostedFileBase file)
        {
            var model = new FileUploadViewModel();
            //validation on file input
            if (file == null || !file.ContentType.Contains("image"))
            {
                model.errorMessage = "You must select a png file to upload";
                ViewBag.Hidden = "display: none";
                ViewBag.UserName = "";
                ViewBag.ImageNumber = "";
                return View("Index", model);
            }

            MemoryStream ms = new MemoryStream();
            file.InputStream.CopyTo(ms);
            byte[] fileBytes = ms.GetBuffer();
            ms.Close();

            DetectionResponse response = _fps.DetectSignature(fileBytes, Path.GetFileName(file.FileName));

            //if sig detection success return user/image id else return error
            if (response.Status == ResultStatus.Success)
            {
                model.errorMessage = null;
                if (response.UserName != null)
                    ViewBag.UserName = response.UserName;

                ViewBag.ImageNumber = response.ImageNumber;
                ViewBag.Hidden = "";
                return View("Index", model);
            }
            else
            {
                model.errorMessage = response.Message;
                ViewBag.Hidden = "display: none";
                ViewBag.UserName = "";
                ViewBag.ImageNumber = "";
                return View("Index", model);
            }
        }