protected void btnAdd_Click(object sender, EventArgs e) { if (Page.IsValid) { SupplySystem.Area area = null; if (this.ViewState["Mode"] == null) // Add mode { if (string.IsNullOrEmpty(this.hdnUserID.Value)) { this.lblMessage.Text = "مدیر منطقه را انتخاب کنید"; return; } DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<SupplySystem.User>(u => u.UsersInRoles); db.LoadOptions = dlo; area = new SupplySystem.Area { AreaCode = Public.ToInt(this.txtAreaCode.Text), AreaName = this.txtAreaName.Text, ProvinceID = Public.ToByte(ConfigurationManager.AppSettings["DefaultProvinceId"]) }; SupplySystem.User user = db.Users.First<SupplySystem.User>(u => u.UserID == Public.ToInt(this.hdnUserID.Value)); user.UsersInRoles.First<SupplySystem.UsersInRole>().AreaCode = area.AreaCode; db.Areas.InsertOnSubmit(area); } else if (this.ViewState["Mode"].ToString() == "edit") // Edit mode { area = db.Areas.First<SupplySystem.Area>(ar => ar.AreaCode == Public.ToInt(this.txtAreaCode.Text)); area.AreaName = this.txtAreaName.Text; area.UsersInRoles.First<SupplySystem.UsersInRole>().AreaCode = area.AreaCode; } db.SubmitChanges(); this.grdAreas.DataSource = db.Areas.Where<SupplySystem.Area>(ar => ar.ProvinceID == Public.ToByte(ConfigurationManager.AppSettings["DefaultProvinceId"])).Select(ar => new { ar.AreaCode, ar.AreaName }).OrderBy(ar => ar.AreaCode).ToList(); this.grdAreas.DataBind(); this.lblMessage.Text = Public.SUCCESSMESSAGE; ClearControls(); } }
private void detach_Areas(Area entity) { this.SendPropertyChanging(); entity.Province = null; }
private void attach_Areas(Area entity) { this.SendPropertyChanging(); entity.Province = this; }
partial void DeleteArea(Area instance);
partial void UpdateArea(Area instance);
partial void InsertArea(Area instance);