Ejemplo n.º 1
0
        public JsonResult UpdateUserEmail()
        {
            string newEmail = Request.Params["NewEmail"];

            DTO dto = AccountUtils.UpdateUserEmail(newEmail, User.Identity.Name);

            var    u   = new UrlHelper(this.Request.RequestContext);
            string url = "http://" + this.Request.Url.Host + u.RouteUrl("Default", new { Controller = "Account", Action = "Logon" });

            //send to old and new emails
            Utility.SendHtmlEmail("Halfpint - Email Change", new string[] { newEmail }, null, dto.Message, Server, url);
            Utility.SendHtmlEmail("Halfpint - Email Change", new string[] { dto.Bag.ToString() }, null, dto.Message, Server, url);

            return(Json(dto));
        }
Ejemplo 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));
        }