Exemple #1
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"));
        }
Exemple #2
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());
        }