Example #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int ID = Convert.ToInt32(hClientID.Value);
            if (ID != 0 && (hCurrStatus.Value != rcmbStatus.SelectedValue))
            {
                objClientDA.UpdateClientStatusDA(ID, rcmbStatus.SelectedValue, Convert.ToInt32(Session["UserID"]));
                popClients();
                lbtnBack_Click(null, null);
            }
            else
            {
                // Business rule check
                if ((ID != 0) && (Convert.ToInt32(txtNoUsers.Text) < Convert.ToInt32(hActiveUserCnt.Value)))
                {
                    dvValidationMsg.Visible = true;
                    lblValidationMsg.Text = objError.getMessage("SS0003");
                }
                else if (ID != 0)
                {
                    if (objUserDA.isUserExistDA(txtAdminEmail.Text.Trim(), Convert.ToInt32(hAdminID.Value)))
                    {
                        dvValidationMsg.Visible = true;
                        lblValidationMsg.Text = objError.getMessage("AM0012");
                    }
                }
                else if (ID == 0)
                {
                    if (objUserDA.isUserExistDA(txtAdminEmail.Text.Trim()))
                    {
                        dvValidationMsg.Visible = true;
                        lblValidationMsg.Text = objError.getMessage("AM0002");
                    }
                }

                if (dvValidationMsg.Visible == false)
                {
                    #region add/update client profile

                    objClientBE.ClientID = ID;
                    objClientBE.ClientName = txtClientName.Text;
                    objClientBE.Address1 = txtAddress.Text;
                    objClientBE.City = txtCity.Text;
                    objClientBE.State = txtState.Text;
                    objClientBE.CountryID = Convert.ToInt32(rcmbCountry.SelectedValue);
                    objClientBE.PostCode = txtPostcode.Text;
                    objClientBE.Phone = txtPhone.Text;
                    objClientBE.Website = txtWebsite.Text;
                    objClientBE.IndustryID = Convert.ToInt32(rcmbIndustry.SelectedValue);
                    objClientBE.AnnualRevID = Convert.ToInt32(rcmbRevenue.SelectedValue);
                    objClientBE.NoOfUsers = Convert.ToInt32(txtNoUsers.Text);
                    objClientBE.CurrentPkgSubscribed = chkPackage.SelectedValue;
                    objClientBE.ClientStatus = rcmbStatus.SelectedValue; // "Active";
                    objClientBE.CreatedBy = Convert.ToInt32(Session["UserID"]);
                    ID = objClientDA.SaveClientProfileDA(objClientBE);
                    #endregion

                    #region Creating required folder structure for client
                    if (hClientID.Value == "0" && ID != 0)
                    {
                        DocAccess objDocAccess = new DocAccess();
                        if (!objDocAccess.InitClientFolders(ID))
                            lblFilterError.Text = objError.getMessage("AM0010");
                    }
                    #endregion

                    #region Updating primary contact and administrator
                    if (ID != 0)
                    {
                        lblClientError.Text = "";
                        //Saving Contact
                        ContactBE objContact = new ContactBE();
                        objContact.ClientID = ID;
                        objContact.ContactID = Convert.ToInt32(hContactID.Value);
                        objContact.Contactname = txtContactName.Text;
                        objContact.Phone = txtContactPhone.Text;
                        objContact.Email = txtContactEmail.Text;
                        objContact.Department = txtContactDepart.Text;
                        objContact.JobTitle = txtJobTitle.Text;
                        objClientDA.SaveClientContactDA(objContact);

                        //Saving Primary administrator

                        UserBE objUserBE = new UserBE();

                        objUserBE.UserID = Convert.ToInt32(hAdminID.Value);
                        objUserBE.EmailID = txtAdminEmail.Text;
                        objUserBE.FirstName = txtAdminFName.Text;
                        objUserBE.LastName = txtAdminLName.Text;
                        objUserBE.Address = "";
                        objUserBE.Telephone = txtAdminPhone.Text;
                        objUserBE.Role = "Admin";
                        objUserBE.ClientID = ID;
                        objUserBE.Department = txtAdminDept.Text;
                        objUserBE.UserStatus = "Active";
                        objUserBE.isPrimary = true;
                        objUserBE.CreatedBy = Convert.ToInt32(Session["UserID"]);

                        if (Convert.ToInt32(hAdminID.Value) != 0)
                        {
                            if (!objUserDA.UpdateUserRecord(objUserBE, objUserBE.UserID))
                                lblClientError.Text = objError.getMessage("AM0012");
                        }
                        else
                        {
                            string rndPasswd = RandomPassword.Generate();
                            objUserBE.Password = rndPasswd;

                            if (objUserDA.AddUserAccountDA(objUserBE) > 0)
                            {
                                // Emailing the account details to user
                                int reqID = SaveToEmailJob(txtAdminEmail.Text, rndPasswd);
                                if (reqID > 0)
                                {
                                    EmailApp objEmailing = new EmailApp();
                                    objEmailing.SendEmail(reqID);
                                }
                            }
                        }
                        // Following commented on 2/20/13 - J, as these logics ar moved inside the sp for add/edit client profile
                        //if (hClientID.Value == "0")
                        //    objClientDA.InitClientConfigDA(ID, chkPackage.SelectedValue, false);
                        //else if (hCurrPkg.Value != chkPackage.SelectedValue)
                        //    objClientDA.InitClientConfigDA(ID, chkPackage.SelectedValue, true);

                        //Session["clientID"] = ID.ToString();
                        //Response.Redirect("ClientConfig/");
                        popClients();
                        if (lblClientError.Text == "")
                            lbtnBack_Click(null, null);
                    }
                    #endregion
                    if (lblClientError.Text == "")
                        clearAll();
                }
            }
        }
Example #2
0
        public int SaveClientContactDA(ContactBE objContactBE)
        {
            int contactID = objContactBE.ContactID;
            string sql1 = "";
            if (contactID == 0)
                sql1 = DBQuery.sqlContactInsert;
            else
                sql1 = DBQuery.sqlContactUpdate;

            try
            {
                using (MySqlConnection sqlCon = new MySqlConnection(Constant.EBirdConnectionString))
                {
                    using (MySqlCommand sqlCmd = new MySqlCommand(sql1, sqlCon))
                    {
                        sqlCon.Open();
                        sqlCmd.CommandType = CommandType.Text;
                        sqlCmd.Parameters.Add(new MySqlParameter("@ContactName", objContactBE.Contactname));
                        sqlCmd.Parameters.Add(new MySqlParameter("@Phone", objContactBE.Phone));
                        sqlCmd.Parameters.Add(new MySqlParameter("@Email", objContactBE.Email));
                        sqlCmd.Parameters.Add(new MySqlParameter("@Department", objContactBE.Department));
                        sqlCmd.Parameters.Add(new MySqlParameter("@Address1", objContactBE.Address1));
                        sqlCmd.Parameters.Add(new MySqlParameter("@clientID", objContactBE.ClientID));
                        sqlCmd.Parameters.Add(new MySqlParameter("@ContactStatus", "Active"));
                        sqlCmd.Parameters.Add(new MySqlParameter("@jobTitle", objContactBE.JobTitle));
                        if (contactID != 0)
                            sqlCmd.Parameters.Add(new MySqlParameter("@ContactID", objContactBE.ContactID));

                        sqlCmd.ExecuteNonQuery();
                        sqlCon.Close();
                    }
                    return contactID;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }