protected void grdDistricts_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Edit") { int index = Convert.ToInt32(e.CommandArgument); string value = this.grdDistricts.DataKeys[index].Values["id"].ToString(); Response.Redirect("edit.aspx?id=" + value.ToString()); } if (e.CommandName == "DeleteDistrict") { int index = Convert.ToInt32(e.CommandArgument); string value = this.grdDistricts.DataKeys[index].Values["id"].ToString(); _district = _dal.GetDistrictsById(new Guid(value)); _district.isDeleted = true; _district.deletedDate = DateTime.Now; _dal.SkyLarkArenaEntities.SaveChanges(); Response.Redirect("default.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { try { MasterPagePropertiesInterface m = Master as MasterPagePropertiesInterface; if (m != null) m.themeTitle = "Districts Edit"; district _district = new district(); if (!IsPostBack) { string id = Request.QueryString["id"]; if (id != "00000000-0000-0000-0000-000000000000") { _guid = string.IsNullOrEmpty(id) ? new Guid() : new Guid(id); _district = _dal.GetDistrictsById(_guid); } txtName.Text = _district.name; txtPrefix.Text = Convert.ToString(_district.prefix); } } catch(Exception ex) { } }
protected void btnSave_Click(object sender, EventArgs e) { district _district = new district(); string id = Request.QueryString["id"]; if (id != "00000000-0000-0000-0000-000000000000") { _guid = string.IsNullOrEmpty(id) ? new Guid() : new Guid(id); } _district = _dal.GetDistrictsById(_guid); _district.name = txtName.Text; _district.prefix = Convert.ToInt32(txtPrefix.Text); _district.isDeleted = false; if (id == "00000000-0000-0000-0000-000000000000") { _dal.SkyLarkArenaEntities.districts.Add(_district); } _dal.SkyLarkArenaEntities.SaveChanges(); Response.Redirect("default.aspx"); }
public district GetDistrictsById(Guid _districtId) { try { if (_districtId == Guid.Empty) { district _district = new district(); return _district; } else { var q = SkyLarkArenaEntities.districts.Where(p => p.id == _districtId && p.isDeleted == false); if (q == null) throw new EntityContextException(string.Format("A district could not be found {0}!", _districtId)); else return q.ToList()[0]; } } catch (Exception ex) { throw new EntityContextException("GetPlayerBYID failed.", ex); } }