Exemple #1
0
        protected void btnSendInvite_Click(object sender, EventArgs e)
        {
            try
            {
                int      totalchkboxes      = Convert.ToInt32(totalaccountscheck.InnerHtml.ToString());
                string[] totalchkboxesArray = new string[totalchkboxes];


                int jj = 0;
                for (int i = 0; i < totalchkboxes; i++)
                {
                    if (Page.Request.Form["chkbox_" + i + ""] != null)
                    {
                        totalchkboxesArray[jj] = Page.Request.Form["chkbox_" + i + ""].ToString();
                        jj++;
                    }
                }

                if (jj > 0)
                {
                    if (!string.IsNullOrEmpty(txtEmail.Text) && !string.IsNullOrEmpty(txtFirstName.Text) && !string.IsNullOrEmpty(txtLastName.Text))
                    {
                        if (txtEmail.Text != "Enter Email Address" && txtFirstName.Text != "First Name" && txtLastName.Text != "Last Name")
                        {
                            // if (rbAdmin.Checked || rbUser.Checked)
                            // {
                            //if (rbAdmin.Checked)
                            //{
                            //    AccessLevel = "admin";
                            //}
                            //else if (rbUser.Checked)
                            //{
                            //    AccessLevel = "user";
                            //}

                            // if (AccessLevel != string.Empty)
                            // {
                            TeamRepository teamrepo = new TeamRepository();
                            Team           team     = null;
                            Guid           gpId     = (Guid)Session["GroupId"];
                            User           user     = (User)Session["LoggedUser"];
                            if (!teamrepo.checkTeamExists(txtEmail.Text, user.Id, gpId))
                            {
                                team                  = new Team();
                                team.Id               = Guid.NewGuid();
                                team.GroupId          = (Guid)Session["GroupId"];
                                team.FirstName        = txtFirstName.Text;
                                team.LastName         = txtLastName.Text;
                                team.StatusUpdateDate = DateTime.Now;
                                team.EmailId          = txtEmail.Text;
                                team.UserId           = user.Id;
                                team.InviteStatus     = 1;
                                team.InviteDate       = DateTime.Now;
                                // team.AccessLevel = AccessLevel;
                                teamrepo.addNewTeam(team);
                            }
                            else
                            {
                                // team = teamrepo.getMemberByEmailId(user.Id, txtEmail.Text);

                                Response.Write("<script>alert(\"Already invited in this group\");</script>");
                            }

                            MailSender.SendInvitationEmail(team.FirstName + " " + team.LastName, user.UserName, team.EmailId, team.Id);
                            if (totalchkboxesArray.Count() != 0)
                            {
                                TeamMemberProfileRepository teammemberprofilerepo = new TeamMemberProfileRepository();
                                foreach (var item in totalchkboxesArray)
                                {
                                    try
                                    {
                                        if (!string.IsNullOrEmpty(item))
                                        {
                                            string[]          itemarray  = item.Split('_');
                                            TeamMemberProfile teammember = new TeamMemberProfile();
                                            teammember.Id               = Guid.NewGuid();
                                            teammember.ProfileId        = itemarray[1];
                                            teammember.ProfileType      = itemarray[0];
                                            teammember.Status           = 1;
                                            teammember.StatusUpdateDate = DateTime.Now;
                                            teammember.TeamId           = team.Id;
                                            if (!teammemberprofilerepo.checkTeamMemberProfile(teammember.TeamId, teammember.ProfileId))
                                            {
                                                teammemberprofilerepo.addNewTeamMember(teammember);
                                            }
                                            else
                                            {
                                                teammemberprofilerepo.updateTeamMember(teammember);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex.StackTrace);
                                    }
                                }
                                Response.Redirect("InviteMember.aspx");
                            }
                            txtFirstName.Text = "";
                            txtLastName.Text  = "";
                            txtEmail.Text     = "";
                            //  rbAdmin.Checked = false;
                            // rbUser.Checked = false;
                            Label1.Text = "Invitation Sends";
                            //  }

                            // }

                            //else
                            //{
                            //    Response.Write("<script>alert(\"Please fill Group Name\");</script>");
                            //}
                        }
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "MyFun1", "disp_confirm();", true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }