示例#1
0
        /// <summary>
        /// Updates specified application
        /// </summary>
        /// <param name="appl"> proposed SFApp object update </param>
        /// <returns> updated SFApp object as reflected in DB </returns>
        public async Task <SFApp> UpdateSFAppAsync(SFApp appl)
        {
            _context.SFApps.Update(appl);
            await _context.SaveChangesAsync();

            return(await GetSFAppAsync(appl.Email));
        }
示例#2
0
        // Submit App
        public async Task OnPostSubmitAppl()
        {
            SFAppVM = await _app.BuildSFAppVM(User.Identity.Name);

            SFApp appl = await _app.GetSFAppAsync(User.Identity.Name);

            appl.AppStatus = AppStatus.Submitted;
            appl           = await _app.UpdateSFAppAsync(appl);

            if (appl.AppStatus == AppStatus.Submitted)
            {
                // build email
                Email message = new Email()
                {
                    Recipient = User.Identity.Name,
                    ConfigSet = "",
                    Subject   = "Your Silton Foundation grant application has been received!",
                    BodyHtml  = @"<html>
                                <head></head>
                                <body>
                                  <h1>Thank you for applying!</h1>
                                </body>
                                </html>",
                };
                bool emailStatus = await message.Send();
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Submit failed. Please try again.");
            }
            //await _eval.CreateEvaluationsForAppAsync(appl.ID);
        }
示例#3
0
        public async Task OnGetStartApplication()
        {
            // get logged in user's info
            AppUser user = await _user.FindByEmailAsync(User.Identity.Name);

            // if user is not 'Applicant', add Applicant role
            if (!await _user.IsInRoleAsync(user, AppRoles.Applicant))
            {
                await _user.AddToRoleAsync(user, AppRoles.Applicant);
            }

            // create new application
            SFApp newApp = await _app.CreateSFAppAsync(user.Email);

            SFAppVM = await _app.BuildSFAppVM(User.Identity.Name);
        }
示例#4
0
        /// <summary>
        /// Builds a new SFAppViewModel object from the SFApp associated with user who owns 'email'
        /// </summary>
        /// <param name="email"> email of user whose app to prepare as SFAppViewModel </param>
        /// <returns> SFAppViewModel for user's current SFApp, or 'null' if no open SFApp exists </returns>
        public async Task <SFAppViewModel> BuildSFAppVM(string email)
        {
            SFApp appl = await GetSFAppAsync(email);

            if (appl != null)
            {
                SFAppViewModel sFApp = new SFAppViewModel();
                sFApp.Appl         = appl;
                sFApp.AppResponses = await _response.GetAllAppResponsesAsync(appl.ID);

                sFApp.Questions = await _question.GetAppQuestionsAsync(sFApp.AppResponses);

                sFApp.Categories = _question.GetAllCategories(sFApp.Questions);
                return(sFApp);
            }
            return(null);
        }
示例#5
0
        /// <summary>
        /// Creates new application for specified user if no open application exists.
        /// If open application exists, returns the open application.
        /// </summary>
        /// <param name="email"> user's email </param>
        /// <returns> new (or existing open) application for specified user </returns>
        public async Task <SFApp> CreateSFAppAsync(string email)
        {
            var query = await GetSFAppAsync(email);

            AppUser applicant = await _user.FindByEmailAsync(email);

            // if no open application exists, create one
            if (query == null || query.Closed != null)
            {
                // create new SFApp object
                SFApp app = new SFApp()
                {
                    Name       = $"{applicant.FirstName} {applicant.LastName}",
                    Email      = email,
                    Created    = DateTime.Now,
                    AppYear    = DateTime.Now.Year,
                    LastChange = DateTime.Now,
                    AppStatus  = AppStatus.Draft,
                    Closed     = null
                };

                // add new SFApp to DB
                await _context.SFApps.AddAsync(app);

                await _context.SaveChangesAsync();

                // retrieve newly created app from DB
                SFApp newApp = await GetSFAppAsync(email);

                // build responses and associate with app ID
                foreach (Question question in await _question.GetAllActiveQuestionsAsync())
                {
                    await _response.CreateAppResponseAsync(newApp.ID, question.ID);
                }
            }
            // return newly created application
            return(query);
        }