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.");
        }
    }
 protected void DeleteDepartment(int dept_id)
 {
     department = getDepartment(dept_id);
     if (department == null)
     {
         SetErrorMessage(WebConstants.Messages.Error.INVALID_ID);
     }
     else
     {
         try
         {
             department.FlgDeleted = true;
             estateAgentDB.SaveChanges();
             SetInfoMessage(WebConstants.Messages.Information.RECORD_DELETED);
             GridView1.DataBind();
         }
         catch
         {
             SetErrorMessage(WebConstants.Messages.Error.CONNECTION_ERROR);
         }
       }
 }
 /// <summary>
 /// Create a new RefDepartment object.
 /// </summary>
 /// <param name="sequence">Initial value of the Sequence property.</param>
 public static RefDepartment CreateRefDepartment(global::System.Int32 sequence)
 {
     RefDepartment refDepartment = new RefDepartment();
     refDepartment.Sequence = sequence;
     return refDepartment;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the RefDepartments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRefDepartments(RefDepartment refDepartment)
 {
     base.AddObject("RefDepartments", refDepartment);
 }