Esempio n. 1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AcquiredItem = await _context.AcquiredItem
                           .Include(r => r.ItemType).FirstOrDefaultAsync(m => m.ID == id);

            if (AcquiredItem == null)
            {
                return(NotFound());
            }
            if (AcquiredItem.Attachment == null)
            {
                return(NotFound());
            }
            ContentDisposition cd = new ContentDisposition
            {
                FileName = AcquiredItem.AttachmentFileName,
                Inline   = true
            };

            Response.Headers.Add("Content-Disposition", cd.ToString());
            return(File(AcquiredItem.Attachment, AcquiredItem.AttachmentContentType));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            AcquiredItem originalItem = await _context.AcquiredItem.FirstOrDefaultAsync(m => m.ID == AcquiredItem.ID);

            if (originalItem != null && Request.Form.Files.Count == 0)
            {
                AcquiredItem.Attachment            = originalItem.Attachment;
                AcquiredItem.AttachmentFileName    = originalItem.AttachmentFileName;
                AcquiredItem.AttachmentContentType = originalItem.AttachmentContentType;
            }
            _context.Entry(originalItem).State = EntityState.Detached;  // detach from original item so you can attach to new one
            if (Request.Form.Files.Count > 0)
            {
                Stream s = Request.Form.Files[0].OpenReadStream();
                if (s.Length < 20 * 1024 * 1024)
                {
                    byte[] buffer = new byte[s.Length];
                    s.Read(buffer, 0, (int)s.Length);
                    s.Close();
                    AcquiredItem.Attachment            = buffer;
                    AcquiredItem.AttachmentFileName    = Request.Form.Files[0].FileName;
                    AcquiredItem.AttachmentContentType = Request.Form.Files[0].ContentType;
                }
                else
                {
                    s.Close();
                    ModelState.AddModelError(string.Empty, "The attachment is too large.  The maximum size is 20MB.");
                    return(Page());
                }
            }

            _context.Attach(AcquiredItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AcquiredItemExists(AcquiredItem.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("../Assessments/Details", new { id = AcquiredItem.AssessmentID }));
        }
 public IActionResult OnGet(int?AssessmentID)
 {
     if (AssessmentID == null)
     {
         return(NotFound());
     }
     ViewData["ItemTypeID"]    = new SelectList(_context.ItemType, "ID", "Name");
     ViewData["AssessmentID"]  = (int)AssessmentID;
     AcquiredItem              = new AcquiredItem();
     AcquiredItem.ItemTypeID   = 1;
     AcquiredItem.AssessmentID = (int)AssessmentID;
     return(Page());
 }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AcquiredItem = await _context.AcquiredItem
                           .Include(r => r.ItemType).FirstOrDefaultAsync(m => m.ID == id);

            if (AcquiredItem == null)
            {
                return(NotFound());
            }
            ViewData["AssessmentID"] = AcquiredItem.AssessmentID;
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AcquiredItem = await _context.AcquiredItem.FindAsync(id);

            int parentID = AcquiredItem.AssessmentID;

            if (AcquiredItem != null)
            {
                _context.AcquiredItem.Remove(AcquiredItem);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("../Assessments/Details", new { id = parentID }));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Assessment.Add(Assessment);
            await _context.SaveChangesAsync();

            int id = Assessment.ID;

            // now get all the related records to the assessment type,
            // so that we can add the required items to the
            // acquired items (with the "Acquired" checkbox false, of course).
            Assessment = await _context.Assessment
                         .Include(s => s.AssessmentType)
                         .ThenInclude(s => s.RequiredItems)
                         .Include(s => s.AcquiredItems)
                         .AsNoTracking()
                         .FirstOrDefaultAsync(m => m.ID == id);

            foreach (RequiredItem ri in Assessment.AssessmentType.RequiredItems)
            {
                AcquiredItem ai = new AcquiredItem();
                ai.Description           = ri.Description;
                ai.Attachment            = ri.Attachment;
                ai.AttachmentFileName    = ri.AttachmentFileName;
                ai.AttachmentContentType = ri.AttachmentContentType;
                ai.AssessmentID          = id;
                ai.Acquired   = false;
                ai.ItemName   = ri.ItemName;
                ai.ItemType   = ri.ItemType;
                ai.ItemTypeID = ri.ItemTypeID;
                _context.AcquiredItem.Add(ai);
            }
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Details", new { id = Assessment.ID }));
        }