protected void btnUpload_Click(object sender, EventArgs e)
    {
        using (CsvReader csv = new CsvReader(new StreamReader(fileUpload.FileContent), true))
        {
            int count = 0;
            RefDepartment orderTA = new RefDepartment();
            int fieldCount = csv.FieldCount;
            string[] headers = csv.GetFieldHeaders();

            while (csv.ReadNextRecord())
            {
                string fullAddress = csv["address_line1"] + " " + csv["address_line2"] + csv["address_line3"] + csv["address_line4"] + csv["address_line5"] + csv["address_post_code"];

                PropertyDetail property = new PropertyDetail();
                property.AddressLine1 = csv["address_line1"];
                property.AddressLine2 = csv["address_line2"];
                property.AddressLine3 = csv["address_line3"];
                property.AddressLine4 = csv["address_line4"];
                property.AddressLine5 = csv["address_line5"];
                property.AddressPostCode = csv["address_post_code"];
                property.AddressFull = fullAddress;
                property.CompanySequence = loggedInUserCoId;
                property.CreatedBy = loggedInUserId;
                property.LastAmendedBy = loggedInUserId;
                property.DateCreated = System.DateTime.Now;
                property.DateLastAmended = System.DateTime.Now;
                property.FlgDeleted = false;
                estateAgentDB.PropertyDetails.AddObject(property);
                estateAgentDB.SaveChanges();

                PropertyFieldDepartment propFieldDepartment = new PropertyFieldDepartment();
                propFieldDepartment.CompanySequence = loggedInUserCoId;
                propFieldDepartment.PropertySequence = property.Sequence;
                propFieldDepartment.DepartmentSequence = int.Parse(ddlDepartments.SelectedValue);
                propFieldDepartment.CreatedBy = loggedInUserId;
                propFieldDepartment.LastAmendedBy = loggedInUserId;
                propFieldDepartment.DateCreated = System.DateTime.Now;
                propFieldDepartment.DateLastAmended = System.DateTime.Now;
                property.PropertyFieldDepartments.Add(propFieldDepartment);

                PropertyFieldCategory propFieldCategory = new PropertyFieldCategory();
                propFieldCategory.CompanySequence = loggedInUserCoId;
                propFieldCategory.PropertySequence = property.Sequence;
                propFieldCategory.CategorySequence = int.Parse(ddlCategory.SelectedValue);
                propFieldCategory.CreatedBy = loggedInUserId;
                propFieldCategory.LastAmendedBy = loggedInUserId;
                propFieldCategory.DateCreated = System.DateTime.Now;
                propFieldCategory.DateLastAmended = System.DateTime.Now;
                property.PropertyFieldCategories.Add(propFieldCategory);

                estateAgentDB.SaveChanges();

                count++;
            }

            SetInfoMessage(count + " properties added to the system.");
        }
    }
 /// <summary>
 /// Deprecated Method for adding a new object to the PropertyFieldDepartments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPropertyFieldDepartments(PropertyFieldDepartment propertyFieldDepartment)
 {
     base.AddObject("PropertyFieldDepartments", propertyFieldDepartment);
 }
 /// <summary>
 /// Create a new PropertyFieldDepartment object.
 /// </summary>
 /// <param name="sequence">Initial value of the Sequence property.</param>
 public static PropertyFieldDepartment CreatePropertyFieldDepartment(global::System.Int32 sequence)
 {
     PropertyFieldDepartment propertyFieldDepartment = new PropertyFieldDepartment();
     propertyFieldDepartment.Sequence = sequence;
     return propertyFieldDepartment;
 }