using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Acme.EFExample.EFDAL; using Acme.EFExample.EFDAL.Entity; using Acme.EFExample.Website.Objects; namespace Acme.EFExample.Website { public partial class CountryEdit : Acme.EFExample.Website.Objects.BasePersistablePage { protected override void OnInit(EventArgs e) { base.OnInit(e); cmdSave.Click += new EventHandler(SaveData); } protected override void SetupBindings(EFExampleEntities context) { int id = this.Request.GetURLInteger("id"); var item = context.Country.Where(x => x.CountryId == id).FirstOrDefault(); lblHeader.Text = "Edit Country"; if (item == null) { lblHeader.Text = "New Country"; item = CreateObject(context) as Country; } this.Mapper.Map(txtName, item, Acme.EFExample.EFDAL.Entity.Country.FieldNameConstants.Name); } protected override Widgetsphere.EFCore.DataAccess.NHEntityObject CreateObject(EFExampleEntities context) { //Create a new object and set any default properties when requested var item = new Country(); context.Country.AddObject(item); return item; } protected override void OnDataSavedSucess(EventArgs e) { //On save success go to the list page base.OnDataSavedSucess(e); HttpContext.Current.Response.Redirect("/countrylist.aspx"); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)