partial void DeleteFormerBusiness(FormerBusiness instance);
partial void InsertFormerBusiness(FormerBusiness instance);
partial void UpdateFormerBusiness(FormerBusiness instance);
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); } }