protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }

        string Email          = null;
        bool   EmailChanged   = false;
        string AdCompanyEmail = null;

        AdCompany company = null;

        if (IsNewMode)
        {
            Membership.UserCreateResults results = Membership.CreateAdCompany(txtEmail.Text, out company);
            switch (results)
            {
            default:
            case Membership.UserCreateResults.UnknownError:
                Master.MessageCenter.DisplayErrorMessage(SuppliersStrings.GetText(@"MessageCreateFailedUnknown"));
                return;

            case Membership.UserCreateResults.AlreadyExists:
                Master.MessageCenter.DisplayErrorMessage(SuppliersStrings.GetText(@"MessageCreateFailedAlreadyExists"));
                return;

            case Membership.UserCreateResults.InvalidEmailAddress:
                Master.MessageCenter.DisplayErrorMessage(SuppliersStrings.GetText(@"MessageCreateFailedEmailAddressInvalid"));
                return;

            case Membership.UserCreateResults.Success:
                break;
            }
            CompanyId           = company.CompanyId;
            company.CreatedDate = DateTime.Now;
            AdCompanyEmail      = company.Email;
        }
        else
        {
            company        = AdCompany.FetchByID(CompanyId);
            AdCompanyEmail = company.Email;
        }
        company.BusinessName = txtBusinessName.Text;
        company.ContactName  = txtContactName.Text;
        company.ContactPhone = txtContactPhone.Text;
        company.Phone        = txtPhone.Text;
        company.Description  = txtDescription.Text;
        company.Save();

        if (IsNewMode)
        {
            CompanyId = company.CompanyId;
        }

        if (company.Email != txtEmail.Text.Trim().NormalizeEmail())
        {
            if (AdCompany.FetchByEmail(txtEmail.Text.Trim().NormalizeEmail()) != null)
            {
                Master.MessageCenter.DisplayWarningMessage(AppUsersStrings.GetText(@"MessageEmailChangeFailed"));
            }
            else
            {
                company.Email = txtEmail.Text.Trim().NormalizeEmail();
                EmailChanged  = true;
            }
        }

        AdCompanyEmail = company.Email;
        company.Save();

        if (IsNewMode)
        {
            string successMessage = AdvertisementsStrings.GetText(@"MessageCompanyCreated");
            string url            = @"EditAdCompany.aspx?Email=" + AdCompanyEmail + "&CompanyId=" + company.CompanyId;
            url += @"&message-success=" + Server.UrlEncode(successMessage);
            Response.Redirect(url, true);
        }
        else
        {
            string successMessage = SuppliersStrings.GetText(@"MessageSupplierSaved");
            if (EmailChanged)
            {
                string url = @"EditAdCompany.aspx?message-success=" + Server.UrlEncode(successMessage) + "&CompanyId=" + company.CompanyId;
                if (CompanyId != company.CompanyId)
                {
                    url += @"&Email=" + AdCompanyEmail;
                }
                Response.Redirect(url, true);
            }
            else
            {
                Master.MessageCenter.DisplaySuccessMessage(successMessage);
                LoadView();
            }
        }
    }
Example #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            string UserEmail    = null;
            bool   EmailChanged = false;

            if (IsNewMode)
            {
                User user = null;
                Membership.UserCreateResults results = Membership.CreateUser(txtEmail.Text, txtPassword.Text.Trim(), out user);
                switch (results)
                {
                default:
                case Membership.UserCreateResults.UnknownError:
                    Master.MessageCenter.DisplayErrorMessage(UsersStrings.GetText(@"MessageCreateFailedUnknown"));
                    return;

                case Membership.UserCreateResults.AlreadyExists:
                    Master.MessageCenter.DisplayErrorMessage(UsersStrings.GetText(@"MessageCreateFailedAlreadyExists"));
                    return;

                case Membership.UserCreateResults.InvalidEmailAddress:
                    Master.MessageCenter.DisplayErrorMessage(UsersStrings.GetText(@"MessageCreateFailedEmailAddressInvalid"));
                    return;

                case Membership.UserCreateResults.Success:
                    break;
                }
                if (chkIsLocked.Checked != user.IsLocked)
                {
                    user.IsLocked = chkIsLocked.Checked;
                    user.Save();
                }
                UserId    = user.UserId;
                UserEmail = user.Email;
            }
            else
            {
                User user = core.DAL.User.FetchByID(UserId);
                UserEmail = user.UniqueEmail;

                if (user.UniqueEmail != txtEmail.Text.NormalizeEmail() ||
                    user.IsLocked != chkIsLocked.Checked)
                {
                    try
                    {
                        user.Email       = txtEmail.Text.Trim();
                        user.UniqueEmail = user.Email.NormalizeEmail();
                        user.IsLocked    = chkIsLocked.Checked;
                        user.Save();
                        if (user.UniqueEmail != UserEmail)
                        {
                            UserEmail    = user.Email;
                            EmailChanged = true;
                        }
                    }
                    catch
                    {
                        Master.MessageCenter.DisplayWarningMessage(UsersStrings.GetText(@"MessageEmailChangeFailed"));
                    }
                }

                if (txtPassword.Text.Length > 0)
                {
                    Membership.UserPasswordChangeResults results;
                    if (UserId == SessionHelper.UserId())
                    {
                        results = Membership.ChangeUserPassword(user.Email, txtCurrentPassword.Text, txtPassword.Text);
                    }
                    else
                    {
                        results = Membership.ChangeUserPassword(user.Email, txtPassword.Text);
                    }
                    switch (results)
                    {
                    default:
                        Master.MessageCenter.DisplayWarningMessage(UsersStrings.GetText(@"MessagePasswordChangeFailedUnknown"));
                        break;

                    case Membership.UserPasswordChangeResults.PasswordDoNotMatch:
                        Master.MessageCenter.DisplayWarningMessage(UsersStrings.GetText(@"MessagePasswordChangeBadOldPassword"));
                        break;

                    case Membership.UserPasswordChangeResults.Success:
                        break;
                    }
                }
                UserEmail = user.Email;
            }

            if (IsNewMode)
            {
                string successMessage = UsersStrings.GetText(@"MessageUserCreated");
                string url            = @"EditUser.aspx?Email=" + UserEmail;
                url += @"&message-success=" + Server.UrlEncode(successMessage);
                Response.Redirect(url, true);
            }
            else
            {
                string successMessage = UsersStrings.GetText(@"MessageUserSaved");
                if (EmailChanged)
                {
                    string url = @"EditUser.aspx?message-success=" + Server.UrlEncode(successMessage);
                    if (UserId != SessionHelper.UserId())
                    {
                        url += @"&Email=" + UserEmail;
                    }
                    Response.Redirect(url, true);
                }
                else
                {
                    Master.MessageCenter.DisplaySuccessMessage(successMessage);
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            string SupplierEmail = null;
            bool   EmailChanged  = false;

            AppSupplier supplier = null;

            if (IsNewMode)
            {
                Membership.UserCreateResults results = Membership.CreateSupplier(txtEmail.Text, txtPassword.Text.Trim(), Convert.ToInt64(ddlCity.SelectedValue), out supplier);
                switch (results)
                {
                default:
                case Membership.UserCreateResults.UnknownError:
                    Master.MessageCenter.DisplayErrorMessage(SuppliersStrings.GetText(@"MessageCreateFailedUnknown"));
                    return;

                case Membership.UserCreateResults.AlreadyExists:
                    Master.MessageCenter.DisplayErrorMessage(SuppliersStrings.GetText(@"MessageCreateFailedAlreadyExists"));
                    return;

                case Membership.UserCreateResults.InvalidEmailAddress:
                    Master.MessageCenter.DisplayErrorMessage(SuppliersStrings.GetText(@"MessageCreateFailedEmailAddressInvalid"));
                    return;

                case Membership.UserCreateResults.Success:
                    break;
                }
                SupplierId    = supplier.SupplierId;
                SupplierEmail = supplier.Email;
                //supplier.OrderDisplay = OrderDisplay.GetLastOrder() + 1;
            }
            else
            {
                supplier      = core.DAL.AppSupplier.FetchByID(SupplierId);
                SupplierEmail = supplier.Email;
            }
            supplier.BusinessName = txtBusinessName.Text;

            if (ddlIsProduct.SelectedValue == "prod")
            {
                supplier.IsProduct = true;
                supplier.IsService = false;
            }
            else
            {
                supplier.IsProduct = false;
                supplier.IsService = true;
            }
            //supplier.IsProduct = chkIsProduct.Checked;
            //supplier.IsService = chkIsService.Checked;
            supplier.IsPremium    = chkIsPremium.Checked;
            supplier.IsLocked     = chkIsLocked.Checked;
            supplier.ContactName  = txtContactName.Text;
            supplier.ContactPhone = txtContactPhone.Text;
            supplier.Phone        = txtPhone.Text;
            supplier.CityId       = Convert.ToInt64(ddlCity.SelectedValue);
            supplier.Street       = txtStreet.Text;
            supplier.HouseNum     = txtHouseNum.Text;
            try
            {
                string city = ddlCity.SelectedItem.Text;
                //var address = (city != "" ? city + " " : "") +" "+ (txtStreet.Text != "" ? txtStreet.Text+" " : "") + (txtHouseNum.Text != "" ? txtHouseNum.Text : "");
                var locationService = new GoogleLocationService();
                var point           = (city.Trim() != "" ? locationService.GetLatLongFromAddress(city) : new MapPoint());
                supplier.AddressLocation = new Geometry.Point(point.Latitude, point.Longitude);
            }
            catch (Exception) {
                supplier.AddressLocation = new Geometry.Point(0, 0);
            }
            supplier.HouseNum = txtHouseNum.Text;

            supplier.Precent     = txtPrecent.Text != "" ?Convert.ToInt32(txtPrecent.Text):0;
            supplier.SumPerMonth = txtSumPerMonth.Text != "" ? Convert.ToInt32(txtSumPerMonth.Text) : 0;
            //supplier.StatusJoinBid = chkIsStatusJoinBid.Checked;
            //supplier.AllowChangeStatusJoinBid = chkAllowChangeStatusJoinBid.Checked;
            //supplier.MaxWinningsNum =txtMaxWinningsNum.Text != "" ? Convert.ToInt32(txtMaxWinningsNum.Text) : 0;
            supplier.MastercardCode = txtMastercardCode.Text;
            supplier.Save();

            if (IsNewMode)
            {
                SupplierId = supplier.SupplierId;
                //if (chkIsStatusJoinBid.Checked == false)//handel
                //{
                //    (new Query(SupplierProduct.TableSchema).Where(SupplierProduct.Columns.SupplierId, SupplierId).Delete()).Execute();
                //    ProductCollection pcol = ProductCollection.FetchByQuery(new Query(Product.TableSchema).Where(Product.Columns.IsDeleted, false));
                //    foreach (Product item in pcol)
                //    {
                //        SupplierProduct sp = new SupplierProduct();
                //        sp.SupplierId = SupplierId;
                //        sp.ProductId = item.ProductId;
                //        sp.Gift = "";
                //        sp.Save();
                //    }
                //}
            }
            //if (chkIsService.Checked)
            if (ddlIsProduct.SelectedValue != "prod")
            {
                foreach (ListItem item in ddlServices.Items)
                {
                    if (item.Selected)
                    {
                        SupplierService supplierService = SupplierService.FetchByID(Convert.ToInt64(item.Value), SupplierId);
                        if (supplierService == null)
                        {
                            supplierService            = new SupplierService();
                            supplierService.SupplierId = SupplierId;
                            supplierService.ServiceId  = Convert.ToInt64(item.Value);
                            supplierService.Save();
                        }
                    }
                    else
                    {
                        SupplierService.Delete(Convert.ToInt64(item.Value), SupplierId);
                    }
                }
            }
            else
            {
                SupplierController.DeleteAllSupplierServices(SupplierId);
            }

            if (supplier.Email != txtEmail.Text.Trim().NormalizeEmail())
            {
                if (AppSupplier.FetchByEmail(txtEmail.Text.Trim().NormalizeEmail()) != null)
                {
                    Master.MessageCenter.DisplayWarningMessage(AppUsersStrings.GetText(@"MessageEmailChangeFailed"));
                }
                else
                {
                    supplier.Email          = txtEmail.Text.Trim().NormalizeEmail();
                    supplier.UniqueIdString = supplier.Email;//email.NormalizeEmail();
                    SupplierEmail           = supplier.Email;
                    EmailChanged            = true;
                }
            }

            SupplierEmail = supplier.Email;
            supplier.Save();

            if (txtPassword.Text.Length > 0)
            {
                if (txtConfirmPassword.Text != txtPassword.Text)
                {
                    Master.MessageCenter.DisplayErrorMessage(SuppliersStrings.GetText(@"SupplierNewPasswordConfirmInvalid"));
                    return;
                }
                Membership.UserPasswordChangeResults results;
                results = Membership.ChangeSupplierPassword(supplier.Email, txtPassword.Text);
                switch (results)
                {
                default:
                    Master.MessageCenter.DisplayWarningMessage(SuppliersStrings.GetText(@"MessagePasswordChangeFailedUnknown"));
                    break;

                case Membership.UserPasswordChangeResults.PasswordDoNotMatch:
                    Master.MessageCenter.DisplayWarningMessage(SuppliersStrings.GetText(@"MessagePasswordChangeBadOldPassword"));
                    break;

                case Membership.UserPasswordChangeResults.Success:
                    break;
                }
            }

            if (IsNewMode)
            {
                string successMessage = SuppliersStrings.GetText(@"MessageSupplierCreated");
                string url            = @"EditSupplier.aspx?Email=" + SupplierEmail + "&SupplierId=" + supplier.SupplierId;
                url += @"&message-success=" + Server.UrlEncode(successMessage);
                Response.Redirect(url, true);
            }
            else
            {
                string successMessage = SuppliersStrings.GetText(@"MessageSupplierSaved");
                if (EmailChanged)
                {
                    string url = @"EditSupplier.aspx?message-success=" + Server.UrlEncode(successMessage) + "&SupplierId=" + supplier.SupplierId;
                    if (SupplierId != supplier.SupplierId)
                    {
                        url += @"&Email=" + SupplierEmail;
                    }
                    Response.Redirect(url, true);
                }
                else
                {
                    Master.MessageCenter.DisplaySuccessMessage(successMessage);
                    LoadView();
                }
            }
        }