Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var session = await _context.GetSessionAsync(SessionID);

            var document = new Document
            {
                SessionID = this.SessionID,
                Session   = session
            };

            document = await MemoryStreamExtention.FileToDocumentAsync(FileUpload, document);

            var success = await _context.AddDocumentAsync(document);

            if (!success)
            {
                return(RedirectToPage("/Error"));
            }

            return(RedirectToPage("./Details", new { id = SessionID }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            // Get the Assingment
            AssignmentID = Assignment.AssignmentID;
            var assignment = await _context.GetAssignmentAsync(Assignment.AssignmentID);

            var document = new Document
            {
                AssignmentID = Assignment.AssignmentID,
                Assignment   = assignment
            };

            document = await
                       MemoryStreamExtention.FileToDocumentAsync(FileUpload, document);

            var documentSuccess = await _context.AddDocumentAsync(document);

            var assignmentSuccess = true;

            if (assignment.DateCompleted == new DateTime())
            {
                assignment.DateCompleted = DateTime.Now;
                assignmentSuccess        = await _context.UpdateAssignmentAsync(assignment);
            }

            if (documentSuccess && assignmentSuccess)
            {
                var protege = await _context.GetProtegeByIDAsync(assignment.Session.Course.Pair.ProtegeID);

                var mentor = await _context.GetMentorByIDAsync(assignment.Session.Course.Pair.MentorID);

                var client = await _context.GetClientByIDAsync(assignment.Session.Course.Pair.ClientID);

                var subject = $"{protege?.AppUser?.Email} uploaded Assignment {assignment?.Title}";
                var message = "<h1>Assignment Uploaded</h1>" +
                              $"<p>The Assigment <strong>{assignment.Title}</strong> was submitted by <strong>{protege?.AppUser?.Email}</strong> at <strong>{assignment?.DateCompleted}</strong></p>";

                if (protege != null && mentor != null)
                {
                    await _emailSender.SendEmailAsync(protege.AppUser.Email, subject, message);
                }

                if (mentor != null)
                {
                    await _emailSender.SendEmailAsync(mentor.AppUser.Email, subject, message);
                }

                if (client != null)
                {
                    await _emailSender.SendEmailAsync(client.AppUser.Email, subject, message);
                }

                return(RedirectToPage("./Details", new { id = assignment.AssignmentID }));
            }

            return(RedirectToPage("/Error"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The OnPostAsync method uploads the document to the specified resource
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync()
        {
            //checks to see if the Model State is valid
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //Creates a new Document
            var document = new Document
            {
            };

            //Passed the FileUpload model and the recently created document to the FileToDocumentAsync function int he applicationDbContext file to put it in the database in bytes.
            document = await MemoryStreamExtention.FileToDocumentAsync(FileUpload, document);

            //Creates a new resouce and fills in certain areas of the model and associates the document with the resource.
            var resource = new Resource
            {
                Category  = FileUpload.Category,
                Name      = Name,
                Type      = "File",
                DateAdded = DateTime.Now,
                CourseID  = courseID,

                Documents = new List <Document>
                {
                    document
                }
            };


            //Adds the resource to the database
            var success = await _context.CreateResourceAsync(resource);

            if (success)
            {
                //Redirects the mentor to the specified course
                return(RedirectToPage("../Mentor/Course/Index", new { id = resource.CourseID }));
            }
            else
            {
                return(RedirectToPage("/Error"));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var document = new Document
            {
            };

            document = await MemoryStreamExtention.FileToDocumentAsync(FileUpload, document);

            var success = await _context.AddDocumentAsync(document);

            if (!success)
            {
                return(RedirectToPage("/Error"));
            }

            return(Page());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var session = await _context.GetSessionAsync(SessionID);

            if (session == null)
            {
                return(RedirectToPage("/Error"));
            }

            var fileUpload = new FileUpload
            {
                Category = "Agenda",
                Document = FileUpload
            };

            var document = new Document();

            document = await MemoryStreamExtention.FileToDocumentAsync(fileUpload, document);

            var agenda = new Agenda
            {
                CreationDate = DateTime.Now,
                Name         = Name,
                SessionID    = SessionID,
                Session      = session,
                Document     = document
            };

            var success = await _context.AddAgendaAsync(agenda);

            if (success)
            {
                var protege = await _context.GetProtegeByIDAsync(session.Course.Pair.ProtegeID);

                var mentor = await _context.GetMentorByIDAsync(session.Course.Pair.MentorID);

                var client = await _context.GetClientByIDAsync(session.Course.Pair.ClientID);

                var subject = $"{protege?.AppUser?.Email} uploaded Agenda {agenda.Name}";
                var message = "<h1>Agenda Uploaded</h1>" +
                              $"<p>The Assigment <strong>{agenda.Name}</strong> was submitted by <strong>{protege?.AppUser?.Email}</strong> at <strong>{agenda.CreationDate}</strong></p>";

                if (protege != null)
                {
                    await _emailSender.SendEmailAsync(protege.AppUser.Email, subject, message);
                }
                if (mentor != null)
                {
                    await _emailSender.SendEmailAsync(mentor.AppUser.Email, subject, message);
                }
                if (client != null)
                {
                    await _emailSender.SendEmailAsync(client.AppUser.Email, subject, message);
                }

                return(RedirectToPage("/Sessions/Details", new { id = session.SessionID }));
            }

            return(RedirectToPage("./Index"));
        }