Initialize() public method

public Initialize ( string username, bool isAuthenticated ) : void
username string
isAuthenticated bool
return void
Example #1
0
        public static ProfileBase Create(string username, bool isAuthenticated)
        {
            ProfileBase profile     = null;
            Type        profileType = ProfileParser.GetProfileCommonType(HttpContext.Current);

            if (profileType != null)
            {
                profile = (ProfileBase)Activator.CreateInstance(profileType);
            }
            else
            {
                profile = (ProfileBase) new DefaultProfile();
            }

            profile.Initialize(username, isAuthenticated);
            return(profile);
        }
Example #2
0
        private static ProfileBase CreateMyInstance(string username, bool isAuthenticated)
        {
            Type profileType;

            if (HostingEnvironment.IsHosted)
            {
                profileType = BuildManager.GetProfileType();
            }
            else
            {
                profileType = InheritsFromType;
            }
            ProfileBase base2 = (ProfileBase)Activator.CreateInstance(profileType);

            base2.Initialize(username, isAuthenticated);
            return(base2);
        }
Example #3
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        // Private static functions and properties
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        static private ProfileBase CreateMyInstance(string username, bool isAuthenticated)
        {
            Type t;

            if (HostingEnvironment.IsHosted)
            {
                t = BuildManager.GetProfileType();
            }
            else
            {
                t = InheritsFromType;
            }
            ProfileBase hbc = (ProfileBase)Activator.CreateInstance(t);

            hbc.Initialize(username, isAuthenticated);
            return(hbc);
        }
        public static string RenderFullMemberName(string username)
        {
            ProfileBase profile = new ProfileBase();
            profile.Initialize(username,true);

            object profilePropertyValue = profile.GetPropertyValue("FullName");
            string outputValue = username;

            if(profilePropertyValue != null)
            {
                if(!String.IsNullOrEmpty(profilePropertyValue.ToString()))
                {
                    outputValue = profilePropertyValue.ToString();
                }
            }

            return outputValue;
        }
        public ActionResult EditUser(FormCollection form)
        {
            string userkey = form["hdnid"].ToString();
            MembershipUser edituser = Membership.GetUser(new Guid(userkey));
            try
            {

                if (userkey != null)
                {

                    edituser.Email = form["txtemail"].ToString();

                    if (edituser != null)
                    {
                        var profile = new ProfileBase();
                        string selectRole = form["ddRoles"].ToString();
                        bool isInRole = Roles.IsUserInRole(edituser.UserName, selectRole);
                        string[] userCurrentRole = Roles.GetRolesForUser(edituser.UserName);
                        if (!isInRole)
                        {
                            string[] curntrole = Roles.GetAllRoles();
                            if (curntrole.Length > 0)
                            {
                                foreach (string removeRole in curntrole)
                                {
                                    bool isnotinRole = Roles.IsUserInRole(edituser.UserName, removeRole);
                                    if (isnotinRole)
                                    {
                                        Roles.RemoveUserFromRole(edituser.UserName, removeRole);
                                    }
                                }

                            }

                            Roles.AddUserToRole(edituser.UserName, selectRole);
                        }
                        profile.Initialize(edituser.UserName, true);
                        profile.SetPropertyValue("FirstName", form["txtfirstname"].ToString());
                        profile.SetPropertyValue("LastName", form["txtlastname"].ToString());
                        profile.SetPropertyValue("Phone", form["txtphone"].ToString());
                        profile.Save();

                        ViewData["EditUser"] = edituser;

                        Membership.UpdateUser(edituser);
                        ViewData["status"] = "Success";
                        ViewData["msg"] = "User information updated successfully.";
                    }
                }

            }
            catch (Exception ex)
            {
                ViewData["status"] = "Error";
                ViewData["msg"] = "Error in User information update.";
                //return RedirectToAction("AddRole", "Resource");
            }
            ViewData["EditUser"] = edituser;
            ViewData["RoleList"] = GetAllRoles();
            return View("EditUser");
        }
        public ActionResult ViewSchedule(FormCollection form)
        {
            string viewuserkey = form["ddUsersList"].ToString();
            MembershipUserCollection userList = Membership.GetAllUsers();
            List<SelectListItem> itemsUser = new List<SelectListItem>();
            string ediusernamedisplay = "";
            foreach (MembershipUser user in userList)
            {
                if (!Roles.IsUserInRole(user.UserName, "Admin"))
                {

                    var userprofile = new ProfileBase();
                    userprofile.Initialize(user.UserName, true);
                    string fname = userprofile.GetPropertyValue("FirstName").ToString();
                    string lname = userprofile.GetPropertyValue("LastName").ToString();

                    string userkey = user.ProviderUserKey.ToString();
                    if (viewuserkey == userkey)
                    {
                        ediusernamedisplay = fname + " " + lname;
                    }
                    SelectListItem item = new SelectListItem();
                    item.Text = fname + " " + lname;
                    item.Value = userkey;
                    itemsUser.Add(item);

                }
            }
            SelectList ddUserlist = new SelectList(itemsUser, "Value", "Text");
            ViewData["Userlist"] = ddUserlist;
            ViewData["ViewUser"] = ediusernamedisplay;
            ViewData["UserProjectList"] = SynergyService.getUserProjects(viewuserkey);
            return View("Schedule");
        }
        public ActionResult Schedule()
        {
            MembershipUserCollection userList = Membership.GetAllUsers();
            List<SelectListItem> itemsUser = new List<SelectListItem>();
            foreach (MembershipUser user in userList)
            {
                if (!Roles.IsUserInRole(user.UserName, "Admin"))
                {

                    var userprofile = new ProfileBase();
                    userprofile.Initialize(user.UserName, true);
                    string fname = userprofile.GetPropertyValue("FirstName").ToString();
                    string lname = userprofile.GetPropertyValue("LastName").ToString();

                    string userkey = user.ProviderUserKey.ToString();
                    SelectListItem item = new SelectListItem();
                    item.Text = fname + " " + lname;
                    item.Value = userkey;
                    itemsUser.Add(item);

                }
            }
            SelectList ddUserlist = new SelectList(itemsUser, "Value", "Text");
            ViewData["Userlist"] = ddUserlist;
            return View();
        }
        public ActionResult EditUser(FormCollection form)
        {
            string userkey = form["hdnid"].ToString();
            MembershipUser edituser = Membership.GetUser(new Guid(userkey));
            try
            {

                if (userkey != null)
                {

                    edituser.Email = form["txtemail"].ToString();

                    if (edituser != null)
                    {
                        var profile = new ProfileBase();
                        string selectRole = form["ddRoles"].ToString();
                        bool isInRole = Roles.IsUserInRole(edituser.UserName, selectRole);
                        string[] userCurrentRole = Roles.GetRolesForUser(edituser.UserName);
                        if (!isInRole)
                        {
                            string[] curntrole = Roles.GetAllRoles();
                            if (curntrole.Length > 0)
                            {
                                foreach (string removeRole in curntrole)
                                {
                                    bool isnotinRole = Roles.IsUserInRole(edituser.UserName, removeRole);
                                    if (isnotinRole)
                                    {
                                        Roles.RemoveUserFromRole(edituser.UserName, removeRole);
                                    }
                                }

                            }

                            Roles.AddUserToRole(edituser.UserName, selectRole);
                        }
                        profile.Initialize(edituser.UserName, true);
                        profile.SetPropertyValue("FirstName", form["txtfirstname"].ToString());
                        profile.SetPropertyValue("LastName", form["txtlastname"].ToString());
                        profile.SetPropertyValue("Phone", form["txtphone"].ToString());
                        profile.Save();

                        PM_MaxUserEfforts userEffort = SynergyService.GetUserEffortById(edituser.UserName);

                        if (form["txteffort"].ToString() == "")
                        {
                            userEffort.MaxEffort = 0;
                        }

                        userEffort.MaxEffort =Convert.ToDecimal(form["txteffort"].ToString());
                        userEffort.aspnet_Users = SynergyService.GetUserByName(edituser.UserName);
                        SynergyService.UpdateUserEffort(userEffort);

                        List<string> ResourceInfo = new List<string>();

                        ResourceInfo.Add(form["txtfirstname"].ToString());
                        //ResourceInfo.Add(form["txtusername"].ToString());

                        ResourceInfo.Add(form["txtemail"].ToString());
                        ResourceInfo.Add(form["ddRoles"].ToString());

                        //ResourceInfo.Add(form["txtfirstname"].ToString());
                        //ResourceInfo.Add(edituser.UserName);
                        //ResourceInfo.Add(form["txtpwd"].ToString());
                        //ResourceInfo.Add(form["txtemail"].ToString());
                        //ResourceInfo.Add(form["ddRoles"].ToString());

                        SendNotificationWhenAccountUpdated(edituser.Email, ResourceInfo);

                        //SendNotificationWhenAccountUpdated(edituser.Email, ResourceInfo);

                        //ResourceInfo = null;

                        if (!SynergyService.IsEmployeeSystemExternal())
                        {
                            try
                            {
                                string nic = form["hdnic"].ToString();

                                EM_Employee employee = SynergyService.GetEmployeebyEmpId(nic);
                                employee.Email = form["txtemail"].ToString();
                                employee.FirstName = form["txtfirstname"].ToString();
                                employee.LastName = form["txtlastname"].ToString();
                                employee.Phone = form["txtphone"].ToString();

                                string departmentId = form["ddlDepartments"].ToString();

                                employee.aspnet_Users = SynergyService.GetUserByName(edituser.UserName);
                                employee.EM_Departments = SynergyService.GetDepartmentbyId(Convert.ToInt32(departmentId));

                                SynergyService.UpdateEmployee(employee);
                                ViewData["DepartmentList"] = GetDepartmentListwithUserSelectedValue(employee.EM_Departments);

                            }
                            catch
                            {
                            }
                        }

                        ViewData["EditUser"] = edituser;

                        Membership.UpdateUser(edituser);
                        ViewData["status"] = "Success";
                        ViewData["msg"] = "User information updated successfully.";
                    }
                }

            }
            catch (Exception )
            {
                ViewData["status"] = "Error";
                ViewData["msg"] = "Error in User information update.";
                //return RedirectToAction("AddRole", "Resource");
            }
            ViewData["EditUser"] = edituser;
            //ViewData["RoleList"] = GetAllRoles();
            //ViewData["DepartmentList"] = GetDepartmentList();
            ViewData["RoleList"] = GetAllRoleswithUserSelectedValue(edituser.UserName);

            return View("EditUser");
        }