protected void saveBtn_Click(object sender, EventArgs e)
    {
        if (!IsValid)
        {
            return;
        }

        var rawId = Request["ID"];

        CustomerManagementModel.Customer customer;
        if (rawId == null)
        {
            customer = new CustomerManagementModel.Customer();
            context.AddToCustomers(customer);
        }
        else
        {
            customer = GetCustomerById(Guid.Parse(rawId));
        }

        customer.FirstName = firstNameField.Text;
        customer.LastName  = LastNameField.Text;
        customer.Address   = addressField.Text;
        customer.CountryID =
            (from c in context.Countries
             where c.Name == countries.Text
             select c.ID)
            .FirstOrDefault();

        context.SaveChanges();
        Response.Redirect("~/CustomerByCountry.aspx");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            return;
        }

        var rawId = Request["ID"];

        CustomerManagementModel.Customer customer = null;
        if (rawId != null)
        {
            customer = GetCustomerById(Guid.Parse(rawId));

            firstNameField.Text = customer.FirstName;
            LastNameField.Text  = customer.LastName;
            addressField.Text   = customer.Address;
        }

        countries.DataSource = context.Countries.OrderBy(c => c.Name);
        countries.DataBind();
        if (rawId != null)
        {
            countries.SelectedValue = customer.Country.ToString();
        }
    }
Beispiel #3
0
 /// <summary>
 /// Create a new Customer object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="lastName">Initial value of the LastName property.</param>
 /// <param name="address">Initial value of the Address property.</param>
 /// <param name="zipCode">Initial value of the ZipCode property.</param>
 /// <param name="city">Initial value of the City property.</param>
 /// <param name="countryID">Initial value of the CountryID property.</param>
 /// <param name="url">Initial value of the Url property.</param>
 /// <param name="creditLimit">Initial value of the CreditLimit property.</param>
 /// <param name="newsSubscriber">Initial value of the NewsSubscriber property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 public static Customer CreateCustomer(global::System.Guid id, global::System.String firstName, global::System.String lastName, global::System.String address, global::System.String zipCode, global::System.String city, global::System.Guid countryID, global::System.String url, global::System.Int32 creditLimit, global::System.Boolean newsSubscriber, global::System.DateTime createdDate, global::System.String createdBy)
 {
     Customer customer = new Customer();
     customer.ID = id;
     customer.FirstName = firstName;
     customer.LastName = lastName;
     customer.Address = address;
     customer.ZipCode = zipCode;
     customer.City = city;
     customer.CountryID = countryID;
     customer.Url = url;
     customer.CreditLimit = creditLimit;
     customer.NewsSubscriber = newsSubscriber;
     customer.CreatedDate = createdDate;
     customer.CreatedBy = createdBy;
     return customer;
 }
Beispiel #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomers(Customer customer)
 {
     base.AddObject("Customers", customer);
 }