public ActionResult SubmitNewReviewItem(ApplicationReviewViewModel model)
        {            
            UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));

            if(ModelState.IsValid)
            {
                model.NewReviewItem.Reviewer = UserManager.FindByName(model.NewReviewItem.Reviewer.UserName);
                model.Applicant = db.Applicants.Where(a => a.Id == model.NewReviewItem.ApplicantId).FirstOrDefault();
                model.NewReviewItem.Status = model.NewReviewItemStatus.GetDisplayName();
                
                model.NewReviewItem.DateTimeCreated = DateTime.Now;
                
                db.Applications.Add(model.NewReviewItem);
                db.SaveChanges();
                
                MessagePayload message = new MessagePayload();
                message.Attachments = new List<MessagePayloadAttachment>();

                message.Attachments.Add(new MessagePayloadAttachment()
                {
                    Text = string.Format(Properties.Settings.Default.AppUpdate_MessageFormatLine2, model.Applicant.Name, model.NewReviewItem.Status, model.NewReviewItem.Reviewer.UserName, model.NewReviewItem.DateTimeCreated.ToString("yyyy-MM-dd HH:mm:ss")),
                    TitleLink = string.Format(Properties.Settings.Default.EveWhoPilotURL, model.Applicant.Name.Replace(" ", "+")),
                    Title = Properties.Settings.Default.AppUpdate_MessageFormatLine1,
                    ThumbUrl = string.Format(Properties.Settings.Default.CharacterImageServerURL, Api.GetCharacterID(model.Applicant.Name), 64.ToString()),
                    Colour = "#FFC200"
                });
                RecruitmentController.SendMessage(message);

                if (model.NewReviewItemStatus == ApplicationReviewViewModel.ApplicationStatus.InScreening)
                {
                    return RedirectToAction("ReviewApplication", new { id = model.NewReviewItem.ApplicantId });
                }
                else
                {
                    return RedirectToAction("ShowApplications");
                }
            }
            return View(model);
        }
        public ActionResult ReviewApplication(int? id)
        {
            UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));

            if (id == null)
            {
                return RedirectToAction("ShowApplications");
            }
            var newReviewModel = new ApplicationReviewViewModel() { };

            newReviewModel.ApplicationInfo = db.Applications.Where(a => a.ApplicantId == id).ToList<Application>();
            if ((newReviewModel.ApplicationInfo.Last().Status == ApplicationReviewViewModel.ApplicationStatus.Accepted.ToString()) || (newReviewModel.ApplicationInfo.Last().Status == ApplicationReviewViewModel.ApplicationStatus.Rejected.ToString()))
            {
                ViewBag.Complete = true;
            }
            else
            {
                ViewBag.Complete = false;
                if(newReviewModel.ApplicationInfo.Last().Status.Replace(" ", "") == ApplicationReviewViewModel.ApplicationStatus.Applied.ToString())
                {
                    newReviewModel.NewReviewItemStatus = ApplicationReviewViewModel.ApplicationStatus.InScreening;
                }
                else if(newReviewModel.ApplicationInfo.Last().Status.Replace(" ", "") == ApplicationReviewViewModel.ApplicationStatus.NeedsAPIMail.ToString())
                {
                    newReviewModel.NewReviewItemStatus = ApplicationReviewViewModel.ApplicationStatus.APIMailSent;
                }
                else if (newReviewModel.ApplicationInfo.Last().Status.Replace(" ", "") == ApplicationReviewViewModel.ApplicationStatus.AwaitingInvitation.ToString())
                {
                    newReviewModel.NewReviewItemStatus = ApplicationReviewViewModel.ApplicationStatus.Accepted;
                }
                else
                {
                    newReviewModel.NewReviewItemStatus = (ApplicationReviewViewModel.ApplicationStatus)Enum.Parse(typeof(ApplicationReviewViewModel.ApplicationStatus), newReviewModel.ApplicationInfo.Last().Status.Replace(" ", ""));
                }
            }

            newReviewModel.Applicant = db.Applicants.Where(a => a.Id == id).FirstOrDefault();
            if((newReviewModel.Applicant.TimeZone == null) || (newReviewModel.Applicant.TimeZone == string.Empty))
            {
                newReviewModel.Applicant.TimeZone = "Unknown";
            }
            newReviewModel.NewReviewItem = new Application() { ApplicantId = newReviewModel.Applicant.Id, Reviewer = UserManager.FindById(User.Identity.GetUserId()) };

            return View(newReviewModel);
        }