public JsonResult Submit()
        {
            var id    = Request.Params["ID"];
            var name  = Request.Params["Name"];
            var email = new[] { Request.Params["Email"] };
            //var empId = Request.Params["EmployeeId"];

            var tests = DbPostTestsUtils.GetTestsCompleted(id);

            if (tests.Count == 0)
            {
                return(Json("no tests"));
            }

            var site  = DbUtils.GetSiteidIdForUser(HttpContext.User.Identity.Name);
            var staff = NotificationUtils.GetStaffForEvent(7, site);

            string siteName = DbUtils.GetSiteNameForUser(User.Identity.Name);

            var u = new UrlHelper(Request.RequestContext);

            Debug.Assert(Request.Url != null, "Request.Url != null");
            var url = "http://" + Request.Url.Host + u.RouteUrl("Default", new { Controller = "Account", Action = "Logon" });

            Utility.SendPostTestsSubmittedMail(staff.ToArray(), email, tests, name, siteName, Server, url);

            _logger.LogInfo("Post-tests submitted: " + name);
            return(Json(""));
        }
        public JsonResult GuardianREALTimeMonitor()
        {
            var id   = Request.Params["id"];
            var name = Request.Params["name"];

            id   = Encoder.HtmlEncode(id);
            name = Encoder.HtmlEncode(name);

            var dto = DbPostTestsUtils.VerifyPostTest("GuardianREALTimeMonitor", Request.Params);

            if (dto.IsSuccessful)
            {
                //get the person id
                var nameId = int.Parse(id);
                //save test as completed
                DbPostTestsUtils.AddAndUpdateTestCompleted(nameId, "Guardian REAL-Time Monitor");
            }

            var incorrect = "";

            if (dto.Messages.Count > 0)
            {
                incorrect = dto.Messages.Aggregate(incorrect, (current, s) => current + (s + ","));
                incorrect = incorrect.Substring(0, incorrect.Length - 1);
            }

            _logger.LogInfo("Post-tests GuardianREALTimeMonitor: " + name + ", " + dto.Message + incorrect);
            return(Json(dto));
        }
        public ActionResult ShowPostTestsDue()
        {
            int siteId = DbUtils.GetSiteidIdForUser(User.Identity.Name);
            var ptndl  = DbPostTestsUtils.GetStaffPostTestsFirstDateCompletedBySite(siteId);

            return(View(ptndl));
        }
        public ActionResult ShowPostTestsCompleted2()
        {
            int siteId = DbUtils.GetSiteidIdForUser(User.Identity.Name);
            var ptel   = DbPostTestsUtils.GetPostTestStaffsTestsCompletedExtended(siteId);

            return(View(ptel));
        }
        public JsonResult AddPostTest(List <PostTest> postTests, string staffId, string staffName)
        {
            if (postTests.Any(pt => string.IsNullOrEmpty(pt.sDateCompleted)))
            {
                return(Json(0));
            }

            int iRet = DbPostTestsUtils.SaveNewPostTestsCompleted(postTests, int.Parse(staffId), staffName);

            return(Json(iRet));
        }
        //new procedure
        public JsonResult GetTestsCompletedActive()
        {
            var staffId  = Request.Params["ID"];
            var siteCode = Request.Params["SiteCode"];
            //var siteLanguage = Request.Params["SiteLanguage"];
            var tests = DbPostTestsUtils.GetStaffPostTestsCompletedCurrentAndActive(staffId, siteCode);
            var email = DbPostTestsUtils.GetPostTestStaffEmail(staffId);

            var retVal = new { email, tests };

            return(Json(retVal));
        }
        public ActionResult UpdateStaffInformation()
        {
            string role = "";

            if (HttpContext.User.IsInRole("Admin"))
            {
                role = "Admin";

                var sites = DbUtils.GetSitesActive();
                if (sites.Count == 0)
                {
                    throw new Exception("There was an error retreiving the sites list from the database");
                }
                sites.Insert(0, new Site {
                    ID = 0, Name = "Select a site", SiteID = ""
                });
                ViewBag.Sites = new SelectList(sites, "ID", "Name");
            }
            ViewBag.Role = role;

            int site = DbUtils.GetSiteidIdForUser(User.Identity.Name);

            ViewBag.Site = site;

            var retDto = DbPostTestsUtils.GetSiteEmployeeInfoForSite(site.ToString());

            ViewBag.EmpRequired = retDto.Stuff.EmpIDRequired;
            if (retDto.Stuff.EmpIDRequired == "true")
            {
                ViewBag.EmpRegex   = retDto.Stuff.EmpIDRegex;
                ViewBag.EmpMessage = retDto.Stuff.EmpIDMessage;
            }
            else
            {
                ViewBag.EmpRegex   = "";
                ViewBag.EmpMessage = "";
            }

            ViewBag.PhoneMessage = retDto.Stuff.PhoneMessage;
            ViewBag.PhoneFormat  = retDto.Stuff.PhoneFormat;

            var list = DbUtils.GetStaffLookupForSite(site.ToString());

            list.Insert(0, new Site {
                ID = 0, Name = "Select a member", SiteID = ""
            });
            ViewBag.Users = new SelectList(list, "ID", "Name");

            ViewBag.IsValid = "true";

            return(View(new StaffEditModel()));
        }
        public ActionResult EditPostTest(string id)
        {
            var site         = DbUtils.GetSiteidIdForUser(User.Identity.Name);
            var siteCode     = DbUtils.GetSiteCodeForUser(User.Identity.Name);
            var tests        = DbPostTestsUtils.GetStaffPostTestsCompletedCurrentAndActive(id, siteCode);
            var staffInfo    = DbUtils.GetStaffInfo(int.Parse(id));
            var postTestView = new PostTestView();

            postTestView.StaffId   = staffInfo.ID;
            postTestView.StaffName = staffInfo.FirstName + " " + staffInfo.LastName;
            postTestView.PostTests = tests;
            return(View(postTestView));
        }
        public ActionResult Initialize(string id)
        {
            var model = new PostTestsInitializeModel();
            var role  = AccountUtils.GetRoleForUser(User.Identity.Name);

            model.Role = role;

            if (role != "Nurse")
            {
                if (id == "0")
                {
                    var dto = DbPostTestsUtils.GetStaffIdByUserName(User.Identity.Name);
                    id = dto.ReturnValue.ToString(CultureInfo.InvariantCulture);
                }
            }
            if (id == "-1")
            {
                return(RedirectToRoute(new { Controller = "Staff" }));
            }

            model.UserId = int.Parse(id);

            var si = DbUtils.GetSiteInfoForUser(User.Identity.Name);

            model.SiteId   = si.Id;
            model.SiteCode = si.SiteId;
            model.Language = si.Language;

            var users = DbPostTestsUtils.GetStaffTestUsersForSite(model.SiteId);

            users.Insert(0, new IDandName(0, "Select Your Name"));

            //check if employee id required
            var retDto = DbPostTestsUtils.CheckIfEmployeeIdRequired(User.Identity.Name);

            model.EmpIdRequired = retDto.Stuff.EmpIDRequired;
            model.EmpIdRegex    = retDto.Stuff.EmpIDRegex;
            model.EmpIdMessage  = retDto.Stuff.EmpIDMessage;

            ViewBag.Users = new SelectList(users, "ID", "Name", id);
            if (id != "0")
            {
                model.Email = DbPostTestsUtils.GetPostTestStaffEmail(id);
            }

            return(View(model));
        }
        public JsonResult IsUserEmployeeIdDuplicate(string employeeId)
        {
            var site = DbUtils.GetSiteidIdForUser(User.Identity.Name);
            var dto  = DbPostTestsUtils.DoesStaffEmployeeIdExist(employeeId, site);

            //if site is dallas
            if (site == 13)
            {
                //if this is a duplicate then get the next non-dupelicate number
                if (dto.ReturnValue == 1)
                {
                    string nexNumber = DbPostTestsUtils.GetNextStaffEmployeeId(employeeId, site);
                    dto.Bag = nexNumber;
                }
            }
            return(Json(dto));
        }
        public JsonResult CreateName()
        {
            var dto = new DTO();

            var siteId    = DbUtils.GetSiteidIdForUser(HttpContext.User.Identity.Name);
            var lastName  = Request.Params["LastName"];
            var firstName = Request.Params["FirstName"];
            var empId     = Request.Params["EmpID"];
            var email     = Request.Params["Email"];

            dto.ReturnValue = DbPostTestsUtils.DoesStaffNameExist(lastName, firstName, siteId);
            if (dto.ReturnValue != 0)
            {
                if (dto.ReturnValue == -1)
                {
                    dto.Message = "There was an error in determinig if this name was already in the database.";
                }
                if (dto.ReturnValue == 0)
                {
                    dto.Message = "This name already exists. Select your name from the drop down list.";
                }

                _logger.LogInfo("PostTests.CreateName - message: " + dto.Message + ", name: " + lastName + "," + firstName + ", site: " + siteId.ToString(CultureInfo.InvariantCulture));
                return(Json(dto));
            }

            dto.ReturnValue = DbPostTestsUtils.AddNurseStaff(lastName, firstName, empId, siteId, email);

            var staff = NotificationUtils.GetStaffForEvent(3, siteId);

            string siteName = DbUtils.GetSiteNameForUser(User.Identity.Name);
            var    u        = new UrlHelper(Request.RequestContext);

            Debug.Assert(Request.Url != null, "Request.Url != null");
            var url = "http://" + Request.Url.Host + u.RouteUrl("Default", new { Controller = "Account", Action = "Logon" });

            Utility.SendNurseAccountCreatedMail(staff.ToArray(), new[] { Request.Params["Email"] }, firstName + " " + lastName, siteName, empId, Server, url);

            _logger.LogInfo("PostTests.CreateName - message: " + dto.Message + ", name: " + lastName + "," + firstName + ", site: " + siteId.ToString(CultureInfo.InvariantCulture));
            return(Json(dto));
        }
        public ActionResult Index()
        {
            var model = new PostTestsInitializeModel();

            model.SiteId   = DbUtils.GetSiteidIdForUser(User.Identity.Name);
            model.SiteCode = DbUtils.GetSiteCodeForUser(User.Identity.Name);

            var users = DbPostTestsUtils.GetStaffTestUsersForSite(model.SiteId);

            users.Insert(0, new IDandName(0, "Select Your Name"));

            //check if employee id required
            var retDto = DbPostTestsUtils.CheckIfEmployeeIdRequired(User.Identity.Name);

            model.EmpIdRequired = retDto.Stuff.EmpIDRequired;
            model.EmpIdRegex    = retDto.Stuff.EmpIDRegex;
            model.EmpIdMessage  = retDto.Stuff.EmpIDMessage;

            ViewBag.Users = new SelectList(users, "ID", "Name");
            return(View(model));
        }
        public ActionResult UpdateStaffInformation()
        {
            int site = DbUtils.GetSiteidIdForUser(User.Identity.Name);

            ViewBag.Site = site;

            var retDto = DbPostTestsUtils.GetSiteEmployeeInfoForSite(site.ToString());

            ViewBag.EmpRequired = retDto.Stuff.EmpIDRequired;
            if (retDto.Stuff.EmpIDRequired == "true")
            {
                ViewBag.EmpRegex   = retDto.Stuff.EmpIDRegex;
                ViewBag.EmpMessage = retDto.Stuff.EmpIDMessage;
            }
            else
            {
                ViewBag.EmpRegex   = "";
                ViewBag.EmpMessage = "";
            }

            ViewBag.PhoneMessage = retDto.Stuff.PhoneMessage;
            ViewBag.PhoneFormat  = retDto.Stuff.PhoneFormat;

            var list = DbUtils.GetStaffLookupForSite(site.ToString());

            list.Insert(0, new Site {
                ID = 0, Name = "Select a member", SiteID = ""
            });
            ViewBag.Users = new SelectList(list, "ID", "Name");

            //show partial if false
            ViewBag.IsValid = "true";

            //ViewBag.Error = "";
            return(View(new StaffEditModel()));
        }
        public JsonResult IsUserEmailDuplicateOtherThan(int id, string email)
        {
            var dto = DbPostTestsUtils.DoesStaffEmailExistOtherThan(id, email);

            return(Json(dto));
        }
        public JsonResult GetSiteEmployeeInfo(string site)
        {
            var retDto = DbPostTestsUtils.GetSiteEmployeeInfoForSite(site);

            return(Json(retDto));
        }
        public JsonResult EditPostTest(List <PostTest> postTests, string staffId, string staffName)
        {
            int iRet = DbPostTestsUtils.SavePostTestsCompleted(postTests, int.Parse(staffId), staffName);

            return(Json(iRet));
        }
        public JsonResult IsUserNameDuplicate(string userName)
        {
            var dto = DbPostTestsUtils.DoesStaffUserNameExist(userName);

            return(Json(dto));
        }
        public ActionResult UpdateStaffInformation([Bind(Exclude = "SiteID,OldRole,OldActive,SendEmail," +
                                                                   "UserName,OldUserName,OldEmail,OldEmployeeID," +
                                                                   "PostTestsCompleted,PostTestsCompletedHistory")] StaffEditModel model)
        {
            //validate model
            if (ModelState.IsValid)
            {
                if (model.Role != "Nurse")
                {
                    model.Email  = model.OldEmail;
                    model.Active = model.OldActive;
                }
                MessageListDTO dto = DbUtils.UpdateStaff(model);
                if (dto.IsSuccessful)
                {
                }
                if (model.OldActive != model.Active)
                {
                    if (model.UserName != null)
                    {
                        var mUser = Membership.GetUser(model.UserName);
                        if (mUser != null)
                        {
                            mUser.IsApproved = model.Active;
                            Membership.UpdateUser(mUser);
                        }
                    }
                }

                return(View("UpdateStaffConfirmationPartial", dto));
            }

            //ModelState.AddModelError("FirstName", "Test Error");
            //string key1 = "";
            //string error = "";
            //foreach (var m in ModelState)
            //{
            //    if (m.Value.Errors.Count > 0)
            //    {
            //        key1 = m.Key;
            //        error = key1 + ":" + m.Value.Errors[0].ErrorMessage;
            //    }
            //}

            //ViewBag.Error = error;
            string role = "";

            if (HttpContext.User.IsInRole("Admin"))
            {
                role = "Admin";

                var sites = DbUtils.GetSitesActive();
                if (sites.Count == 0)
                {
                    throw new Exception("There was an error retreiving the sites list from the database");
                }
                sites.Insert(0, new Site {
                    ID = 0, Name = "Select a site", SiteID = ""
                });
                ViewBag.Sites = new SelectList(sites, "ID", "Name");
            }
            ViewBag.Role = role;

            int site = DbUtils.GetSiteidIdForUser(User.Identity.Name);

            ViewBag.Site = site;

            var list = DbUtils.GetStaffLookupForSite(site.ToString());

            list.Insert(0, new Site {
                ID = 0, Name = "Select a member", SiteID = ""
            });
            ViewBag.Users   = new SelectList(list, "ID", "Name", model.ID.ToString());
            ViewBag.IsValid = "false";

            //need to get tests completed for model - this was not returned from the client
            var postTestsCompleted = DbPostTestsUtils.GetTestsCompleted(model.ID.ToString());
            var ptpc = new PostTestPersonTestsCompleted();

            ptpc.PostTestsCompleted  = postTestsCompleted;
            model.PostTestsCompleted = ptpc;
            return(View(model));
        }
        public JsonResult IsUserEmployeeIdDuplicateOtherThan(int id, string employeeID, int site)
        {
            var dto = DbPostTestsUtils.DoesStaffEmployeeIdExistOtherThan(id, employeeID, site);

            return(Json(dto));
        }
        public JsonResult IsUserEmailDuplicate(string email)
        {
            var dto = DbPostTestsUtils.DoesStaffEmailExist(email);

            return(Json(dto));
        }
        public ActionResult UpdateStaffInformation([Bind(Exclude = "SiteID,OldRole,OldActive,SendEmail," +
                                                                   "UserName,OldUserName,OldEmail,OldEmployeeID," +
                                                                   "PostTestsCompleted,PostTestsCompletedHistory")] StaffEditModel model)
        {
            //validate model
            if (ModelState.IsValid)
            {
                MessageListDTO dto = DbUtils.UpdateStaffAdmin(model);
                if (dto.IsSuccessful)
                {
                }

                if (model.Email != model.OldEmail)
                {
                    DTO dtoEmail = null;
                    if (model.UserName != null)
                    {
                        dtoEmail = AccountUtils.UpdateUserEmail(model.Email, model.UserName);
                    }
                }
                if (model.Role != model.OldRole)
                {
                    if (model.UserName != null)
                    {
                        string[] newroles = { model.Role };
                        UserRolesUtils.SaveAsignedRoles(newroles, model.UserName);
                    }
                }
                if (model.OldActive != model.Active)
                {
                    if (model.UserName != null)
                    {
                        var mUser = Membership.GetUser(model.UserName);
                        if (mUser != null)
                        {
                            mUser.IsApproved = model.Active;
                            Membership.UpdateUser(mUser);
                        }
                    }
                }
                return(View("UpdateStaffConfirmationPartial", dto));
            }

            //ViewBag.Error = error;
            string role = "";

            if (HttpContext.User.IsInRole("Admin"))
            {
                role = "Admin";

                var sites = DbUtils.GetSitesActive();
                if (sites.Count == 0)
                {
                    throw new Exception("There was an error retreiving the sites list from the database");
                }
                sites.Insert(0, new Site {
                    ID = 0, Name = "Select a site", SiteID = ""
                });
                ViewBag.Sites = new SelectList(sites, "ID", "Name");
            }
            ViewBag.Role = role;

            int site = DbUtils.GetSiteidIdForUser(User.Identity.Name);

            ViewBag.Site = site;
            var retDto = DbPostTestsUtils.GetSiteEmployeeInfoForSite(site.ToString());

            ViewBag.EmpRequired = retDto.Stuff.EmpIDRequired;
            if (retDto.Stuff.EmpIDRequired == "true")
            {
                ViewBag.EmpRegex   = retDto.Stuff.EmpIDRegex;
                ViewBag.EmpMessage = retDto.Stuff.EmpIDMessage;
            }
            else
            {
                ViewBag.EmpRegex   = "";
                ViewBag.EmpMessage = "";
            }

            ViewBag.PhoneMessage = retDto.Stuff.PhoneMessage;
            ViewBag.PhoneFormat  = retDto.Stuff.PhoneFormat;

            var list = DbUtils.GetStaffLookupForSite(site.ToString());

            list.Insert(0, new Site {
                ID = 0, Name = "Select a member", SiteID = ""
            });
            ViewBag.Users   = new SelectList(list, "ID", "Name", model.ID.ToString());
            ViewBag.IsValid = "false";

            //need to get tests completed for model - this was not returned from the client
            var postTestsCompleted            = DbPostTestsUtils.GetTestsCompleted(model.ID.ToString());
            PostTestPersonTestsCompleted ptpc = new PostTestPersonTestsCompleted();

            ptpc.PostTestsCompleted  = postTestsCompleted;
            model.PostTestsCompleted = ptpc;

            var roles = Roles.GetAllRoles().ToList();

            ViewBag.Roles = new SelectList(roles, model.Role);

            return(View(model));
        }