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(""));
        }
Esempio n. 2
0
        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));
        }
        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));
        }