Example #1
0
        /// <summary>
        /// Gets file for given id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SignOutSheetUploadModel Get(int id)
        {
            var signOutSheetUploadModel = new SignOutSheetUploadModel();

            var signOutSheetUpload = _signOutSheetUploadRepo.Get(id);

            if (signOutSheetUpload != null)
            {
                signOutSheetUploadModel = _mapper.Map <SignOutSheetUploadModel>(
                    signOutSheetUpload);
            }

            return(signOutSheetUploadModel);
        }
        // Upload scanned SignOut Sheet : Get
        // id is Workshop Id
        public ActionResult Upload(int id = 0)
        {
            // Ensure we have an id > 0
            if (id == 0)
            {
                return(RedirectToAction("Index", "Workshops"));
            }

            var model = new SignOutSheetUploadModel
            {
                WorkshopId = id
            };

            return(View(model));
        }
        public ActionResult Upload(SignOutSheetUploadModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Only allow PDF uploads
            if (model.UploadFile.ContentType != MimeTypes.PDF)
            {
                return(View(model));
            }

            _signOutSheetUploadService.Add(model);

            return(RedirectToAction("Details", "Workshops", new { id = model.WorkshopId }));
        }
Example #4
0
        /// <summary>
        /// Copy data from uploaded file to db.
        /// Returns id of new entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(SignOutSheetUploadModel model)
        {
            var signOutSheetUpload = new SignOutSheetUpload();

            signOutSheetUpload.WorkshopId  = model.WorkshopId;
            signOutSheetUpload.FileName    = model.UploadFile.FileName;
            signOutSheetUpload.FileSize    = model.UploadFile.Length;
            signOutSheetUpload.ContentType = model.UploadFile.ContentType;

            // Get file data from input stream
            using (var memoryStream = new MemoryStream())
            {
                model.UploadFile.CopyTo(memoryStream);
                signOutSheetUpload.FileData = memoryStream.ToArray();
            }

            signOutSheetUpload = _signOutSheetUploadRepo.Add(signOutSheetUpload);

            return(signOutSheetUpload.Id);
        }