public async Task <ActionResult> AddTeamMember(string MemberId, string Name, string EmailId, string PhoneNumber, string Designation, IEnumerable <Int16> EmpRightsId, Int16 EmpRoleId = 0)
        {
            string CorporateId  = User.Identity.GetUserId();
            var    UserDetail   = generic.GetUserDetail(CorporateId);
            var    ClientDetail = cms.GetCorporateProfile(CorporateId).FirstOrDefault();

            if (String.IsNullOrEmpty(MemberId))
            {
                //User Add Mode
                string userName = admin.GenerateUserName();
                var    user     = new ApplicationUser {
                    UserName = userName, Email = EmailId, PhoneNumber = PhoneNumber, EmailConfirmed = true
                };

                var result = await UserManager.CreateAsync(user, "changeme");

                if (result.Succeeded)
                {
                    string RoleId = "Client";

                    var status = UserManager.AddToRole(user.Id, RoleId);
                    if (status.Succeeded)
                    {
                        bool   add         = cms.AddTeamMember(user.Id, CorporateId, UserDetail.SubscriberId, Name, EmailId, PhoneNumber, EmpRoleId, Designation, DateTime.UtcNow, CorporateId);
                        string callbackUrl = await SendEmailConfirmationTokenAsync(ClientDetail.Name, user.Id, "Account activation", userName, PhoneNumber, Name);
                    }
                    if (EmpRightsId != null)
                    {
                        foreach (var right in EmpRightsId)
                        {
                            var success = cms.AddTeamMemberRights(user.Id, right, DateTime.UtcNow, CorporateId);
                        }
                    }
                }
            }
            else
            {
                var regUser = UserManager.FindById(MemberId);
                if (regUser != null)
                {
                    bool result = admin.UpdateUserEmailPhone(regUser.UserName, EmailId, PhoneNumber, true);
                    bool add    = cms.AddTeamMember(MemberId, CorporateId, UserDetail.SubscriberId, Name, EmailId, PhoneNumber, EmpRoleId, Designation, DateTime.UtcNow, CorporateId);
                }
                foreach (var right in EmpRightsId)
                {
                    var success = cms.AddTeamMemberRights(MemberId, right, DateTime.UtcNow, CorporateId);
                }
            }
            return(RedirectToAction("AddTeamMember", "Client"));
        }
Exemple #2
0
        //[Authorize(Roles = "Admin,Client")]
        public ActionResult MyProfile(CorporateProfile MyProfile)
        {
            UserViewModel userdetails = generic.GetUserDetail(User.Identity.GetUserId());

            ViewBag.UserId = userdetails.SubscriberId;
            //If Client has team members with all rights
            if (userdetails.CorporateId != null && userdetails.CorporateId != userdetails.SubscriberId)
            {
                var  TeamDetails = cms.GetTeamMember(userdetails.CorporateId, User.Identity.GetUserId()).FirstOrDefault();
                bool result      = cms.AddTeamMember(User.Identity.GetUserId(), userdetails.CorporateId, userdetails.SubscriberId, MyProfile.Name, MyProfile.AlternateEmail, MyProfile.AlternateContact, TeamDetails.EmpRoleId, TeamDetails.Designation, DateTime.UtcNow, User.Identity.GetUserId());
                return(RedirectToAction("MyProfile", "Dashboard", new { area = "CMS", status = result }));
            }
            else
            {
                bool result = cms.AddCorporateProfile(userdetails.UserId, MyProfile.Name, MyProfile.AlternateContact, MyProfile.AlternateEmail, MyProfile.Nationality, MyProfile.DepartmentId, MyProfile.SubscriberId, DateTime.UtcNow, userdetails.UserId);

                if (!string.IsNullOrEmpty(MyProfile.CorporateId))
                {
                    foreach (string file in Request.Files)
                    {
                        HttpPostedFileBase attachment = Request.Files[file] as HttpPostedFileBase;
                        cms.uploadLogo(MyProfile.CorporateId, attachment);
                    }
                }
                return(RedirectToAction("MyProfile", "Dashboard", new { area = "CMS", status = result }));
            }
        }