Пример #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.Page.IsValid && this.ViewState["UserID"] != null)
        {
            byte selectedRoleId = byte.Parse(this.drpRoles.SelectedValue);
            ListItem item = null;
            db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);
            Ajancy.User user = db.Users.First<Ajancy.User>(u => u.UserID == Public.ToInt(this.ViewState["UserID"]));
            Ajancy.UsersInRole userRole = new Ajancy.UsersInRole { RoleID = selectedRoleId, MembershipDate = DateTime.Now }; ;
            user.UsersInRoles.Add(userRole);

            switch ((Public.Role)selectedRoleId)
            {
                case Public.Role.AjancyManager:
                case Public.Role.AjancySupervisor:
                case Public.Role.AjancySecretary:
                case Public.Role.AjancyPartner:
                    Ajancy.AjancyPartner partner = new Ajancy.AjancyPartner { SubmitDate = DateTime.Now };
                    userRole.AjancyPartners.Add(partner);
                    db.SubmitChanges();
                    item = new ListItem(string.Format("{0} {1}", Public.GetRoleName(userRole.RoleID), "---"), string.Format("{0}|{1}", userRole.UserRoleID, partner.AjancyPartnerID));
                    break;

                case Public.Role.ProvinceManager:
                case Public.Role.AcademyProvince:
                    db.SubmitChanges();
                    item = new ListItem(string.Format("{0} {1}", Public.GetRoleName(selectedRoleId), user.City.Province.Name), string.Format("{0}|0", userRole.UserRoleID));
                    break;

                case Public.Role.CityManager:
                case Public.Role.AcademyCity:
                    db.SubmitChanges();
                    item = new ListItem(string.Format("{0} {1}", Public.GetRoleName(selectedRoleId), user.City.Name), string.Format("{0}|0", userRole.UserRoleID));
                    break;

                default:
                    db.SubmitChanges();
                    item = new ListItem(Public.GetRoleName(selectedRoleId), string.Format("{0}|0", userRole.UserRoleID));
                    break;
            }

            item.Selected = true;
            this.lstRoles.Items.Add(item);
            this.drpRoles.Items.Remove(this.drpRoles.SelectedItem);
            this.lblMessage.Text = "ثبت سمت انجام گردید";
        }
    }
Пример #2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.Page.IsValid)
        {
            int ajancyId = 0;
            Ajancy.Person person = null;
            Ajancy.Ajancy ajancy = new Ajancy.Ajancy();
            Ajancy.BusinessLicense businessLicense = new Ajancy.BusinessLicense();
            db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);

            if (HttpContext.Current.User.IsInRole(Public.Role.AjancyManager.ToString())) // Add mode
            {
                if (db.Ajancies.Any<Ajancy.Ajancy>(j => j.PostalCode == this.txtPlacePostalCode.Text.Trim()))
                {
                    this.lblMessage.Text = "کد پستی واحد تجاری تکراری میباشد";// Duplicate PostalCode
                    return;
                }
                else if (db.Ajancies.Any<Ajancy.Ajancy>(j => j.CityID == int.Parse(this.drpCity.SelectedValue) &&
                                                                                       j.AjancyType != (byte)Public.AjancyType.Academy &&
                                                                                       j.AjancyName.Equals(this.txtAjancyName.Text.Trim())))
                {
                    this.lblMessage.Text = string.Format("آژانسی با نام <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", ajancy.AjancyName, this.drpCity.SelectedItem.Text);
                    return;
                }

                dlo = new DataLoadOptions();
                dlo.LoadWith<Ajancy.Person>(p => p.User);
                dlo.LoadWith<Ajancy.User>(u => u.UsersInRoles);
                dlo.LoadWith<Ajancy.UsersInRole>(ur => ur.AjancyPartners);
                db.LoadOptions = dlo;

                person = db.Persons.First<Ajancy.Person>(p => p.NationalCode == HttpContext.Current.User.Identity.Name);
                Ajancy.AjancyPartner partner = person.User.UsersInRoles.Single<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyManager && ur.LockOutDate == null).AjancyPartners.Single<Ajancy.AjancyPartner>(jp => jp.AjancyID == null);
                ajancy.AjancyPartners.Add(partner);
                ajancy.BusinessLicenses.Add(businessLicense);
                businessLicense.BusinessLicenseRevivals.Add(new Ajancy.BusinessLicenseRevival { StartDate = this.txtStartDate.GeorgianDate.Value, EndDate = this.txtEndDate.GeorgianDate.Value, SubmitDate = DateTime.Now });
                ajancy.SubmitDate = DateTime.Now;
                db.Ajancies.InsertOnSubmit(ajancy);
            }
            else if (!HttpContext.Current.User.IsInRole(Public.Role.AjancyManager.ToString()) && int.TryParse(this.ViewState["AjancyID"].ToString(), out ajancyId)) // Edit mode
            {
                dlo = new DataLoadOptions();
                dlo.LoadWith<Ajancy.Ajancy>(j => j.AjancyUtilities);
                dlo.LoadWith<Ajancy.Ajancy>(j => j.BusinessLicenses);
                dlo.LoadWith<Ajancy.BusinessLicense>(bl => bl.BusinessLicenseRevivals);
                dlo.LoadWith<Ajancy.Ajancy>(j => j.AjancyPartners);
                dlo.LoadWith<Ajancy.AjancyPartner>(jp => jp.UsersInRole);
                dlo.LoadWith<Ajancy.UsersInRole>(ur => ur.User);
                dlo.LoadWith<Ajancy.User>(u => u.Person);
                db.LoadOptions = dlo;

                ajancy = db.Ajancies.FirstOrDefault<Ajancy.Ajancy>(j => j.AjancyID == ajancyId);
                businessLicense = ajancy.BusinessLicenses.First<Ajancy.BusinessLicense>();
                person = ajancy.AjancyPartners.Single<Ajancy.AjancyPartner>(jp => jp.UsersInRole.RoleID == (short)Public.Role.AjancyManager && jp.LockOutDate == null).UsersInRole.User.Person;
            }

            person.FirstName = this.txtFirstName.Text.Trim();
            person.LastName = this.txtLastName.Text.Trim();
            person.Father = this.txtFather.Text.Trim();
            person.BirthCertificateNo = this.txtBirthCertificateNo.Text.Trim();
            person.BirthCertificateSerial = this.txtBirthCertificateSerial.Text.Trim();
            person.BirthCertificateSerie = this.txtBirthCertificateSerie.Text.Trim();
            person.BirthCertificateAlfa = this.drpBirthCertificateAlfa.SelectedValue;
            person.Gender = Public.ToByte(this.drpGender.SelectedValue);
            person.Marriage = Public.ToByte(this.drpMarriage.SelectedValue);
            person.BirthDate = this.txtBirthDate.GeorgianDate.Value;
            person.BirthPlace = this.txtBirthPlace.Text.Trim();
            person.BirthCertificatePlace = this.txtBirthCertificatePlace.Text.Trim();
            person.FamilyMembersCount = this.txtFamilyMembersCount.Text.Trim();
            person.Education = Public.ToByte(this.drpEducation.SelectedValue);
            person.MilitaryService = Public.ToByte(this.drpMilitaryService.SelectedValue);
            person.Religion = Public.ToByte(this.drpReligion.SelectedValue);
            person.Subreligion = this.txtSubreligion.Text.Trim();
            person.JobStatus = Public.ToByte(this.drpJobStatus.SelectedValue);
            person.Phone = this.txtPhone.Text.Trim();
            person.Mobile = this.txtMobile.Text.Trim();
            person.PostalCode = this.txtPostalCode.Text.Trim();
            person.Address = this.txtAddress.Text.Trim();

            ajancy.AjancyType = Public.ToByte(this.drpAjancyType.SelectedValue);
            ajancy.AjancyName = this.txtAjancyName.Text.Trim();
            ajancy.CityID = Public.ToShort(this.drpCity.SelectedValue);
            ajancy.BusinessLicenseType = Public.ToByte(this.drpBusinessLicenseType.SelectedValue);
            ajancy.OfficePosition = Public.ToByte(this.drpOfficePosition.SelectedValue);
            ajancy.OfficeLevel = this.txtOfficeLevel.Text.Trim();
            ajancy.OfficeSpace = this.txtOfficeSpace.Text.Trim();
            ajancy.BalconySpace = this.txtBalconySpace.Text.Trim();
            ajancy.BalconyHeight = this.txtBalconyHeight.Text.Trim();
            ajancy.ParkingSpace = this.txtParkingSpace.Text.Trim();
            ajancy.ParkingState = this.drpParkingState.SelectedIndex == 0 ? true : false;
            ajancy.BusinessScope = this.txtBusinessScope.Text.Trim();
            ajancy.PoliceStation = this.txtPoliceStation.Text.Trim();
            ajancy.Mayor = (byte)this.drpMayor.SelectedIndex;
            ajancy.Address = this.txtPlaceAddress.Text.Trim();
            ajancy.Phone = this.txtBusinessPlacePhone.Text.Trim();
            ajancy.RegisteredPelak = this.txtRegisteredPelak.Text.Trim();
            ajancy.BluePelak = this.txtBluePelak.Text.Trim();
            ajancy.PostalCode = this.txtPlacePostalCode.Text.Trim();
            ajancy.EstateType = Public.ToByte(this.drpEstateType.SelectedValue);
            ajancy.DocumentType = Public.ToByte(this.drpDocumentType.SelectedValue);
            ajancy.PlaceOwner = this.txtPlaceOwner.Text.Trim();

            businessLicense.BusinessLicenseNo = this.txtBusinessLicenseNo.Text.Trim();
            businessLicense.MemberShipCode = this.txtMemberShipCode.Text.Trim();
            businessLicense.NationalCardBarCode = this.txtNationalCardBarCode.Text.Trim();
            businessLicense.SerialNo = this.txtSerialNo.Text.Trim();
            businessLicense.CategoryCode = this.txtCategoryCode.Text.Trim();
            businessLicense.ISIC = this.txtISIC.Text.Trim();
            businessLicense.SubmitDate = DateTime.Now;

            Ajancy.AjancyUtility utility = null;
            foreach (ListItem item in this.lstUtility.Items)
            {
                utility = ajancy.AjancyUtilities.FirstOrDefault<Ajancy.AjancyUtility>(u => u.Utility == Public.ToByte(item.Value));
                if (!item.Selected && utility != null)
                {
                    db.AjancyUtilities.DeleteOnSubmit(utility);
                }
                else if (item.Selected && utility == null)
                {
                    ajancy.AjancyUtilities.Add(new Ajancy.AjancyUtility { Utility = Public.ToByte(item.Value) });
                }
            }

            #region SetPartners

            if (!string.IsNullOrEmpty(this.txtPartnerName1.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerFamily1.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerNationalCode1.Text.Trim()))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode1.Text.Trim());
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode1.Text.Trim(), FirstName = this.txtPartnerName1.Text.Trim(), LastName = this.txtPartnerFamily1.Text.Trim(), SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode1.Text.Trim();
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.txtPartnerName2.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerFamily2.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerNationalCode2.Text.Trim()))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode2.Text.Trim());
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode2.Text.Trim(), FirstName = this.txtPartnerName2.Text.Trim(), LastName = this.txtPartnerFamily2.Text.Trim(), SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode2.Text.Trim();
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.txtPartnerName3.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerFamily3.Text.Trim()) && !string.IsNullOrEmpty(this.txtPartnerNationalCode3.Text.Trim()))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode3.Text.Trim());
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode3.Text.Trim(), FirstName = this.txtPartnerName3.Text.Trim(), LastName = this.txtPartnerFamily3.Text.Trim(), SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode3.Text.Trim();
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }

            #endregion

            try
            {
                db.SubmitChanges();
                DisposeContext();
                this.Session["Ajancy"] = new Ajancy.Ajancy { AjancyID = ajancy.AjancyID, AjancyType = ajancy.AjancyType, AjancyName = ajancy.AjancyName };
                Response.Redirect("~/Message.aspx?mode=4");
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("IX_BusinessLicenses"))
                {
                    this.lblMessage.Text = "شماره پروانه کسب تکراری میباشد";
                }
                else
                {
                    throw ex;
                }
            }
        }
    }
Пример #3
0
		private void attach_UsersInRoles(UsersInRole entity)
		{
			this.SendPropertyChanging();
			entity.Role = this;
		}
Пример #4
0
		private void detach_UsersInRoles(UsersInRole entity)
		{
			this.SendPropertyChanging();
			entity.Role = null;
		}
Пример #5
0
 partial void DeleteUsersInRole(UsersInRole instance);
Пример #6
0
 partial void UpdateUsersInRole(UsersInRole instance);
Пример #7
0
 partial void InsertUsersInRole(UsersInRole instance);
Пример #8
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.Page.IsValid)
        {
            Ajancy.Person person = null;
            Ajancy.Ajancy ajancy = new Ajancy.Ajancy();
            Ajancy.FormerBusiness formerBusiness = new Ajancy.FormerBusiness();
            Ajancy.UsersInRole usersInRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyManager, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now };
            db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);

            if (this.ViewState["AjancyID"] == null) // Add mode
            {
                ajancy.SubmitDate = DateTime.Now;
                db.Ajancies.InsertOnSubmit(ajancy);

                if (this.ViewState["PersonID"] == null) // Add mode
                {
                    person = new Ajancy.Person();
                    person.NationalCode = this.txtNationalCode.Text;
                    person.SubmitDate = DateTime.Now;
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtNationalCode.Text;
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    usersInRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(usersInRole);
                    person.User = user;
                    db.Persons.InsertOnSubmit(person);
                }
                else // Edit mode
                {
                    dlo = new DataLoadOptions();
                    dlo.LoadWith<Ajancy.Person>(p => p.User);
                    dlo.LoadWith<Ajancy.User>(u => u.UsersInRoles);
                    dlo.LoadWith<Ajancy.UsersInRole>(ur => ur.AjancyPartners);
                    db.LoadOptions = dlo;
                    person = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.PersonID == Public.ToInt(this.ViewState["PersonID"]));
                    usersInRole = person.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyManager);
                    if (usersInRole == null)
                    {
                        usersInRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyManager, MembershipDate = DateTime.Now, LockOutDate = DateTime.Now };
                        person.User.UsersInRoles.Add(usersInRole);
                    }
                    usersInRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now, LockOutDate = DateTime.Now });
                }
            }
            else // Edit mode
            {
                dlo = new DataLoadOptions();
                dlo.LoadWith<Ajancy.Ajancy>(j => j.AjancyUtilities);
                dlo.LoadWith<Ajancy.Ajancy>(j => j.BusinessLicenses);
                dlo.LoadWith<Ajancy.Ajancy>(j => j.AjancyPartners);
                dlo.LoadWith<Ajancy.AjancyPartner>(jp => jp.UsersInRole);
                dlo.LoadWith<Ajancy.UsersInRole>(ur => ur.User);
                dlo.LoadWith<Ajancy.User>(u => u.Person);
                db.LoadOptions = dlo;
                ajancy = db.Ajancies.FirstOrDefault<Ajancy.Ajancy>(j => j.AjancyID == Public.ToInt(this.ViewState["AjancyID"]));
                person = ajancy.AjancyPartners.Single<Ajancy.AjancyPartner>(jp => jp.UsersInRole.RoleID == (short)Public.Role.AjancyManager && jp.LockOutDate != null).UsersInRole.User.Person;
            }

            if (ajancy.FormerBusiness == null && !string.IsNullOrEmpty(this.txtFormerBusinessLicenseNo.Text))
            {
                formerBusiness.BusinessLicenseNo = this.txtFormerBusinessLicenseNo.Text;
                formerBusiness.BusinessLicenseDate = this.txtFormerBusinessLicenseDate.GeorgianDate != null ? this.txtFormerBusinessLicenseDate.GeorgianDate : null;
                formerBusiness.BusinessStartDate = this.txtFormerBusinessStartDate.GeorgianDate != null ? this.txtFormerBusinessStartDate.GeorgianDate : null;
                formerBusiness.Board = this.txtFormerBusinessBoard.Text;
                ajancy.FormerBusiness = formerBusiness;
            }
            else if (!string.IsNullOrEmpty(this.txtFormerBusinessLicenseNo.Text))
            {
                ajancy.FormerBusiness.BusinessLicenseNo = this.txtFormerBusinessLicenseNo.Text;
                ajancy.FormerBusiness.BusinessLicenseDate = this.txtFormerBusinessLicenseDate.GeorgianDate != null ? this.txtFormerBusinessLicenseDate.GeorgianDate : null;
                ajancy.FormerBusiness.BusinessStartDate = this.txtFormerBusinessStartDate.GeorgianDate != null ? this.txtFormerBusinessStartDate.GeorgianDate : null;
                ajancy.FormerBusiness.Board = this.txtFormerBusinessBoard.Text;
            }

            person.FirstName = this.txtFirstName.Text;
            person.LastName = this.txtLastName.Text;
            person.Father = this.txtFather.Text;
            person.BirthCertificateNo = this.txtBirthCertificateNo.Text;
            person.BirthCertificateSerial = this.txtBirthCertificateSerial.Text;
            person.BirthCertificateSerie = this.txtBirthCertificateSerie.Text;
            person.BirthCertificateAlfa = this.drpBirthCertificateAlfa.SelectedValue;
            person.Gender = Public.ToByte(this.drpGender.SelectedValue);
            person.Marriage = Public.ToByte(this.drpMarriage.SelectedValue);
            person.BirthDate = this.txtBirthDate.GeorgianDate.Value;
            person.BirthPlace = this.txtBirthPlace.Text;
            person.BirthCertificatePlace = this.txtBirthCertificatePlace.Text;
            person.FamilyMembersCount = this.txtFamilyMembersCount.Text;
            person.Education = Public.ToByte(this.drpEducation.SelectedValue);
            person.MilitaryService = Public.ToByte(this.drpMilitaryService.SelectedValue);
            person.Religion = Public.ToByte(this.drpReligion.SelectedValue);
            person.Subreligion = this.txtSubreligion.Text;
            person.JobStatus = Public.ToByte(this.drpJobStatus.SelectedValue);
            person.Phone = this.txtPhone.Text;
            person.Mobile = this.txtMobile.Text;
            person.PostalCode = this.txtPostalCode.Text;
            person.Address = this.txtAddress.Text;

            ajancy.AjancyType = Public.ToByte(this.drpAjancyType.SelectedValue);
            ajancy.CityID = Public.ToShort(this.drpCity.SelectedValue);
            ajancy.BusinessLicenseType = Public.ToByte(this.drpBusinessLicenseType.SelectedValue);
            ajancy.OfficePosition = Public.ToByte(this.drpOfficePosition.SelectedValue);
            ajancy.OfficeLevel = this.txtOfficeLevel.Text;
            ajancy.OfficeSpace = this.txtOfficeSpace.Text;
            ajancy.BalconySpace = this.txtBalconySpace.Text;
            ajancy.BalconyHeight = this.txtBalconyHeight.Text;
            ajancy.ParkingSpace = this.txtParkingSpace.Text;
            ajancy.ParkingState = this.drpParkingState.SelectedIndex == 0 ? true : false;
            ajancy.BusinessScope = this.txtBusinessScope.Text;
            ajancy.PoliceStation = this.txtPoliceStation.Text;
            ajancy.Mayor = Public.ToByte(this.drpMayor.SelectedValue);
            ajancy.Address = this.txtPlaceAddress.Text;
            ajancy.Phone = this.txtBusinessPlacePhone.Text;
            ajancy.RegisteredPelak = this.txtRegisteredPelak.Text;
            ajancy.BluePelak = this.txtBluePelak.Text;
            ajancy.PostalCode = this.txtPlacePostalCode.Text;
            ajancy.EstateType = Public.ToByte(this.drpEstateType.SelectedValue);
            ajancy.DocumentType = Public.ToByte(this.drpDocumentType.SelectedValue);
            ajancy.PlaceOwner = this.txtPlaceOwner.Text;
            ajancy.WaterBillSerial = this.txtWaterBillSerial.Text;
            ajancy.ElectricityBillSerial = this.txtElectricityBillSerial.Text;
            ajancy.GasBillSerial = this.txtGasBillSerial.Text;

            Ajancy.AjancyUtility utility = null;
            foreach (ListItem item in this.lstUtility.Items)
            {
                utility = ajancy.AjancyUtilities.FirstOrDefault<Ajancy.AjancyUtility>(u => u.Utility == Public.ToByte(item.Value));
                if (!item.Selected && utility != null)
                {
                    db.AjancyUtilities.DeleteOnSubmit(utility);
                }
                else if (item.Selected && utility == null)
                {
                    ajancy.AjancyUtilities.Add(new Ajancy.AjancyUtility { Utility = Public.ToByte(item.Value) });
                }
            }

            #region SetPartners

            if (!string.IsNullOrEmpty(this.txtPartnerName1.Text) && !string.IsNullOrEmpty(this.txtPartnerFamily1.Text) && !string.IsNullOrEmpty(this.txtPartnerNationalCode1.Text))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode1.Text);
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode1.Text, FirstName = this.txtPartnerName1.Text, LastName = this.txtPartnerFamily1.Text, SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode1.Text;
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.txtPartnerName2.Text) && !string.IsNullOrEmpty(this.txtPartnerFamily2.Text) && !string.IsNullOrEmpty(this.txtPartnerNationalCode2.Text))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode2.Text);
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode2.Text, FirstName = this.txtPartnerName2.Text, LastName = this.txtPartnerFamily2.Text, SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode2.Text;
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }
            if (!string.IsNullOrEmpty(this.txtPartnerName3.Text) && !string.IsNullOrEmpty(this.txtPartnerFamily3.Text) && !string.IsNullOrEmpty(this.txtPartnerNationalCode3.Text))
            {
                Ajancy.Person prsn = db.Persons.FirstOrDefault<Ajancy.Person>(p => p.NationalCode == this.txtPartnerNationalCode3.Text);
                Ajancy.UsersInRole userRole = null;
                if (prsn == null)
                {
                    prsn = new Ajancy.Person { NationalCode = this.txtPartnerNationalCode3.Text, FirstName = this.txtPartnerName3.Text, LastName = this.txtPartnerFamily3.Text, SubmitDate = DateTime.Now };
                    Ajancy.User user = new Ajancy.User();
                    user.UserName = this.txtPartnerNationalCode3.Text;
                    user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                    user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                    user.SubmitDate = DateTime.Now;
                    userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                    userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    user.UsersInRoles.Add(userRole);
                    prsn.User = user;
                    db.Persons.InsertOnSubmit(prsn);
                }
                else
                {
                    userRole = prsn.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyPartner);
                    if (userRole == null)
                    {
                        userRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyPartner, MembershipDate = DateTime.Now };
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                        prsn.User.UsersInRoles.Add(userRole);
                    }
                    else if (!userRole.AjancyPartners.Any<Ajancy.AjancyPartner>(jp => jp.AjancyID == ajancy.AjancyID))
                    {
                        userRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                    }
                }
            }

            #endregion

            string url = null;
            try
            {
                db.SubmitChanges();
                url = string.Format("~/Message.aspx?mode=1&c={0}", null);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("IX_Ajancies")) // Duplicate BusinessLicense Request for one place
                {
                    url = "~/Message.aspx?mode=3";
                }
                else if (ex.Message.Contains("Native"))
                {
                    url = "~/Message.aspx?mode=1";
                }
            }
            DisposeContext();
            Response.Redirect(url);
        }
    }
Пример #9
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (this.Page.IsValid)
        {
            int personId = 0;
            int ajancyId = 0;
            Ajancy.Person person = new Ajancy.Person();
            Ajancy.UsersInRole usersInRole = null;
            Ajancy.Ajancy ajancy = new Ajancy.Ajancy();
            Ajancy.BusinessLicense businessLicense = new Ajancy.BusinessLicense();
            db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);

            if (this.ViewState["PersonID"] == null) // Add mode
            {
                Ajancy.User user = new Ajancy.User();
                user.UserName = this.txtNationalCode.Text;
                user.PassWord = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtNationalCode.Text.Trim(), "SHA1");
                user.ProvinceID = Public.ToByte(this.drpProvince.SelectedValue);
                user.CityID = Public.ToShort(this.drpCity.SelectedValue);
                user.SubmitDate = DateTime.Now;
                usersInRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyManager, MembershipDate = DateTime.Now };
                usersInRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                user.UsersInRoles.Add(usersInRole);
                person.SubmitDate = DateTime.Now;
                person.User = user;
                db.Persons.InsertOnSubmit(person);
            }
            else if (int.TryParse(this.ViewState["PersonID"].ToString(), out personId)) // Edit person mode
            {
                dlo = new DataLoadOptions();
                dlo.LoadWith<Ajancy.Person>(p => p.User);
                dlo.LoadWith<Ajancy.User>(u => u.UsersInRoles);
                db.LoadOptions = dlo;

                person = db.Persons.First<Ajancy.Person>(p => p.PersonID == personId);
                usersInRole = person.User.UsersInRoles.SingleOrDefault<Ajancy.UsersInRole>(ur => ur.RoleID == (short)Public.Role.AjancyManager);
                if (usersInRole == null)
                {
                    usersInRole = new Ajancy.UsersInRole { RoleID = (short)Public.Role.AjancyManager, MembershipDate = DateTime.Now };
                    person.User.UsersInRoles.Add(usersInRole);
                }

                if (this.ViewState["AjancyID"] == null)
                {
                    usersInRole.AjancyPartners.Add(new Ajancy.AjancyPartner { Ajancy = ajancy, SubmitDate = DateTime.Now });
                }
            }

            if (this.ViewState["AjancyID"] == null)
            {
                if (db.Ajancies.Any<Ajancy.Ajancy>(j => j.CityID == short.Parse(this.drpCity.SelectedValue) &&
                                                                                j.AjancyType != (byte)Public.AjancyType.Academy &&
                                                                                j.AjancyName.Equals(this.txtAjancyName.Text.Trim())))
                {
                    this.lblMessage.Text = string.Format("آژانسی با نام <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", ajancy.AjancyName, this.drpCity.SelectedItem.Text);
                    return;
                }

                var buslic = from j in db.Ajancies
                             join bl in db.BusinessLicenses on j.AjancyID equals bl.AjancyID
                             where bl.BusinessLicenseNo == this.txtBusinessLicenseNo.Text.Trim() &&
                                        j.CityID == Public.ToShort(this.drpCity.SelectedValue)
                             select new { j.AjancyID };
                foreach (var item in buslic)
                {
                    this.lblMessage.Text = string.Format("آژانسی با شماره پروانه کسب <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", this.txtBusinessLicenseNo.Text, this.drpCity.SelectedItem.Text);
                    return;
                }

                businessLicense.SubmitDate = DateTime.Now;
                ajancy.BusinessLicenses.Add(businessLicense);
            }
            else if (int.TryParse(this.ViewState["AjancyID"].ToString(), out ajancyId)) // Edit ajancy mode
            {
                if (db.Ajancies.Any<Ajancy.Ajancy>(j => j.CityID == int.Parse(this.drpCity.SelectedValue) && j.AjancyID != ajancyId && j.AjancyName.Equals(this.txtAjancyName.Text.Trim())))
                {
                    this.lblMessage.Text = string.Format("آژانسی با نام <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", this.txtAjancyName.Text, this.drpCity.SelectedItem.Text);
                    return;
                }

                var buslic = from j in db.Ajancies
                             join bl in db.BusinessLicenses on j.AjancyID equals bl.AjancyID
                             where bl.BusinessLicenseNo == this.txtBusinessLicenseNo.Text.Trim() &&
                                        j.CityID == Public.ToShort(this.drpCity.SelectedValue) &&
                                        j.AjancyID != ajancyId
                             select new { j.AjancyID };
                foreach (var item in buslic)
                {
                    this.lblMessage.Text = string.Format("آژانسی با شماره پروانه کسب <b>{0}</b> در شهرستان <b>{1}</b> موجود میباشد", this.txtBusinessLicenseNo.Text, this.drpCity.SelectedItem.Text);
                    return;
                }

                ajancy = db.Ajancies.FirstOrDefault<Ajancy.Ajancy>(j => j.AjancyID == ajancyId);
                businessLicense = ajancy.BusinessLicenses.First<Ajancy.BusinessLicense>();
            }

            person.NationalCode = this.txtNationalCode.Text.Trim();
            person.FirstName = this.txtFirstName.Text.Trim();
            person.LastName = this.txtLastName.Text.Trim();
            person.Mobile = this.txtMobile.Text.Trim();
            person.Gender = Public.ToByte(this.drpGender.SelectedValue);

            ajancy.SubmitDate = DateTime.Now;
            ajancy.AjancyType = Public.ToByte(this.drpAjancyType.SelectedValue);
            ajancy.AjancyName = this.txtAjancyName.Text.Trim();
            ajancy.CityID = Public.ToShort(this.drpCity.SelectedValue);
            ajancy.BusinessLicenseType = Public.ToByte(this.drpBusinessLicenseType.SelectedValue);
            ajancy.PostalCode = this.txtPlacePostalCode.Text.Trim();
            ajancy.Address = this.txtPlaceAddress.Text.Trim();
            ajancy.Phone = this.txtBusinessPlacePhone.Text.Trim();
            businessLicense.BusinessLicenseNo = this.txtBusinessLicenseNo.Text.Trim();

            db.SubmitChanges();
            DisposeContext();
            Response.Redirect("~/Message.aspx?mode=4");
        }
    }