private void SaveFranchisor()
    {
        OtherDAL otherDal = new OtherDAL();
        EZip     objczip;

        objczip = otherDal.CheckCityZip(txtCity.Text, txtzip1.Text, ddlState.SelectedValue);

        if (objczip.CityID == 0)
        {
            ClientScript.RegisterStartupScript(typeof(string), "bujscode", "alert('City name entered for contact address is not valid.');", true);
            return;
        }
        else if (objczip.CityID > 0 && objczip.ZipID == 0)
        {
            ClientScript.RegisterStartupScript(typeof(string), "bujscode", "alert('Zip Code entered for contact address, corresponding to its city name, is not valid.');", true);
            return;
        }

        EFranchisorUser franchisoruser = new EFranchisorUser();
        var             address        = new Falcon.Entity.Other.EAddress();
        var             user           = new Falcon.Entity.Other.EUser();
        // format phone no.
        CommonCode objCommonCode = new CommonCode();


        franchisoruser.Active = true;

        address.Address1       = txtaddress1.Text;
        address.Address2       = txtAddress2.Text;
        address.CityID         = objczip.CityID;
        address.StateID        = Convert.ToInt32(ddlState.SelectedValue);
        address.CountryID      = Convert.ToInt32(hfCountryID.Value);
        address.ZipID          = objczip.ZipID;
        user.FirstName         = txtfname.Text;
        user.MiddleName        = txtMiddleName.Text;
        user.LastName          = txtlname.Text;
        user.SSN               = txtSSN.Text;
        user.DOB               = Convert.ToDateTime(txtDOB.Text).ToString();
        user.PhoneHome         = objCommonCode.FormatPhoneNumber(txtphonehome.Text);
        user.PhoneOffice       = objCommonCode.FormatPhoneNumber(txtphoneother.Text);
        user.PhoneCell         = objCommonCode.FormatPhoneNumber(txtphonecell.Text);
        user.EMail1            = txtEmail1.Text;
        user.EMail2            = txtEmail2.Text;
        franchisoruser.User    = user;
        franchisoruser.Address = address;
        Int64 returnresult;

        var currentSession = IoC.Resolve <ISessionContext>().UserSession;


        franchisoruser.ShellDescription = txtabtmself.Text;

        FranchisorDAL franchisorDAL = new FranchisorDAL();

        if (ViewState["IsEdit"].ToString() != string.Empty)
        {
            franchisoruser.User.UserID = Convert.ToInt32(currentSession.UserId);


            returnresult = franchisorDAL.SaveFranchisorUser(franchisoruser, Convert.ToInt32(EOperationMode.Update),
                                                            currentSession.CurrentOrganizationRole.OrganizationId.ToString());
            if (returnresult == 0)
            {
                returnresult = 9999991;
            }

            if (txtPassword.Text.Length > 0)
            {
                var userLoginService = IoC.Resolve <IUserLoginService>();
                userLoginService.ResetPassword(Convert.ToInt32(currentSession.UserId), txtPassword.Text, false, currentSession.CurrentOrganizationRole.OrganizationRoleUserId, false);
            }
            Response.RedirectUser(ResolveUrl("~/App/Franchisor/ProfilePage.aspx"));
        }
        else
        {
            returnresult = franchisorDAL.SaveFranchisorUser(franchisoruser, Convert.ToInt32(EOperationMode.Insert),
                                                            currentSession.CurrentOrganizationRole.OrganizationId.ToString());
            if (returnresult == 0)
            {
                returnresult = 9999990;
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// this method save the franchisor data to the database
    /// </summary>
    private void SaveFranchisor()
    {
        // format phone no.
        CommonCode objCommonCode = new CommonCode();

        OtherDAL otherDal = new OtherDAL();
        EZip     objczip  = otherDal.CheckCityZip(txtCity.Text, txtzip1.Text, ddlstate.SelectedValue);

        if (objczip.CityID == 0)
        {
            ClientScript.RegisterStartupScript(typeof(string), "bujscode", "alert('City name entered for contact address is not valid.');", true);
            return;
        }
        else if (objczip.CityID > 0 && objczip.ZipID == 0)
        {
            ClientScript.RegisterStartupScript(typeof(string), "bujscode", "alert('Zip Code entered for contact address, corresponding to its city name, is not valid.');", true);
            return;
        }

        EFranchisorFranchisorUser franchisorfranchisoruser = new EFranchisorFranchisorUser();
        EFranchisorUser           franchisoruser           = new EFranchisorUser();
        EFranchisor franchisor = new EFranchisor();


        franchisor.Active = true;
        //HealthYes.Web.UI.FranchisorFranchisorUserService.EAddress address = new HealthYes.Web.UI.FranchisorFranchisorUserService.EAddress();
        var address = new Falcon.Entity.Other.EAddress();

        address.Address1  = txtaddress1.Text;
        address.Address2  = string.Empty;
        address.CityID    = objczip.CityID;
        address.StateID   = Convert.ToInt32(ddlstate.SelectedValue);
        address.CountryID = Convert.ToInt32(hfCountryID.Value);
        address.ZipID     = objczip.ZipID;

        //HealthYes.Web.UI.FranchisorFranchisorUserService.EUser user = new HealthYes.Web.UI.FranchisorFranchisorUserService.EUser();
        var user = new Falcon.Entity.Other.EUser();

        user.FirstName   = txtfname.Text;
        user.MiddleName  = txtMiddleName.Text.Length == 0 ? "" : txtMiddleName.Text;
        user.LastName    = txtlname.Text;
        user.SSN         = txtSSN.Text.Length == 0 ? "" : txtSSN.Text;
        user.DOB         = Convert.ToDateTime(txtDOB.Text).ToString();
        user.PhoneHome   = txtphonehome.Text.Length == 0 ? "" : objCommonCode.FormatPhoneNumber(txtphonehome.Text);
        user.PhoneOffice = txtphoneother.Text.Length == 0 ? "" : objCommonCode.FormatPhoneNumber(txtphoneother.Text);
        user.PhoneCell   = txtphonecell.Text.Length == 0 ? "" : objCommonCode.FormatPhoneNumber(txtphonecell.Text);
        user.EMail1      = txtEmail1.Text;
        user.EMail2      = txtEmail2.Text.Length == 0 ? "" : txtEmail2.Text;
        user.HomeAddress = address;

        Ucupdatephotopanel1.GetAllImages();
        franchisoruser.OtherPictures = Ucupdatephotopanel1.Images;
        //franchisoruser.OtherPictures = Ucupdatephotopanel1.Images.ToArray();
        franchisoruser.TeamPicture              = Ucupdatephotopanel1.TeamImage;
        franchisoruser.MyPicture                = Ucupdatephotopanel1.MyImage;
        franchisoruser.User                     = user;
        franchisorfranchisoruser.Franchisor     = franchisor;
        franchisorfranchisoruser.FranchisorUser = franchisoruser;

        var sessionContext = IoC.Resolve <ISessionContext>();

        if (ViewState["FranchisorFranchisorUserID"] != null && ViewState["Email"].ToString().Equals(txtEmail1.Text.Trim()))
        {
            if (ViewState["FranchisorFranchisorUserID"].ToString() != string.Empty)
            {
                FranchisorDAL franchisorDal = new FranchisorDAL();
                var           listFranchisorFranchisorUser =
                    franchisorDal.GetFranchisorFranchisorUser(ViewState["FranchisorFranchisorUserID"].ToString(), 1);
                EFranchisorFranchisorUser[] FFUser = null;

                if (listFranchisorFranchisorUser != null)
                {
                    FFUser = listFranchisorFranchisorUser.ToArray();
                }

                if (FFUser != null)
                {
                    franchisorfranchisoruser.FranchisorUser.User.UserID = Convert.ToInt32(ViewState["UserID"].ToString());

                    franchisorDal.SaveFranchisorFranchisorUser(franchisorfranchisoruser,
                                                               Convert.ToInt32(EOperationMode.Update), sessionContext.UserSession.CurrentOrganizationRole.OrganizationId);

                    Response.RedirectUser(ResolveUrl("~/App/Franchisor/FranchisorAdminUser.aspx?Action=Edited"));
                }
            }
        }
        else
        {
            IUserRepository <User> userRepository = IoC.Resolve <IUserRepository <User> >();
            if (userRepository.UserNameExists(txtEmail1.Text))
            {
                divErrorMsg.Visible   = true;
                divErrorMsg.InnerHtml = "Contact email already exists. Please try another email.";
                return;
            }
            if (ViewState["FranchisorFranchisorUserID"] != null)
            {
                if (ViewState["FranchisorFranchisorUserID"].ToString() != string.Empty)
                {
                    FranchisorDAL franchisorDal = new FranchisorDAL();
                    var           listFranchisorFranchisorUser =
                        franchisorDal.GetFranchisorFranchisorUser(
                            ViewState["FranchisorFranchisorUserID"].ToString(), 1);
                    EFranchisorFranchisorUser[] FFUser = null;

                    if (listFranchisorFranchisorUser != null)
                    {
                        FFUser = listFranchisorFranchisorUser.ToArray();
                    }

                    if (FFUser != null)
                    {
                        franchisorfranchisoruser.FranchisorUser.User.UserID =
                            Convert.ToInt32(ViewState["UserID"].ToString());
                        franchisorDal.SaveFranchisorFranchisorUser(franchisorfranchisoruser,
                                                                   Convert.ToInt32(EOperationMode.Update), sessionContext.UserSession.CurrentOrganizationRole.OrganizationId);

                        Response.RedirectUser(ResolveUrl("~/App/Franchisor/FranchisorAdminUser.aspx?Action=Edited"));
                    }
                }
            }
            else
            {
                //service.AddFranchisorFranchisorUser(franchisorfranchisoruser, usershellmodulerole1, out returnresult, out temp);

                FranchisorDAL franchisorDal = new FranchisorDAL();
                franchisorDal.SaveFranchisorFranchisorUser(franchisorfranchisoruser,
                                                           Convert.ToInt32(EOperationMode.Insert), sessionContext.UserSession.CurrentOrganizationRole.OrganizationId);

                Response.RedirectUser(ResolveUrl("~/App/Franchisor/FranchisorAdminUser.aspx?Action=Added"));
            }
        }
    }