protected void Update_Click(object sender, EventArgs e)
 {
     department = departmentController.actionGetDepartmentByID(Convert.ToInt32((Session["id"])));
     department.code = TextBox1.Text;
     department.phone = TextBox2.Text;
     department.department_name = TextBox3.Text;
     if (TextBox4.Text != string.Empty)
     {
         department.contact_name = TextBox4.Text;
     }
     department.department_head = Convert.ToInt32(TextBox5.Text);
     department.collection_point = Convert.ToInt32(DropDownList1.SelectedValue);
     department.representative_name = TextBox7.Text;
     departmentController.actionUpdateDepartment(department);
     Response.Redirect("DepartmentList.aspx");
 }
 /// <summary>
 /// Create a new Department object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="code">Initial value of the code property.</param>
 /// <param name="department_name">Initial value of the department_name property.</param>
 /// <param name="collection_point">Initial value of the collection_point property.</param>
 public static Department CreateDepartment(global::System.Int32 id, global::System.String code, global::System.String department_name, global::System.Int32 collection_point)
 {
     Department department = new Department();
     department.id = id;
     department.code = code;
     department.department_name = department_name;
     department.collection_point = collection_point;
     return department;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Departments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDepartments(Department department)
 {
     base.AddObject("Departments", department);
 }
        protected void ui_save_button_Click(object sender, EventArgs e)
        {
            DepartmentController departmentController = new DepartmentController();

            Department department = new Department();
            int department_id;

            //getting hidden field id
            if (int.TryParse(ui_id_hiddenfield.Value, out department_id))
            {
                department.id = Convert.ToInt32(ui_id_hiddenfield.Value);
            }
            if (department.id > 0)
            {
                department = departmentController.actionGetDepartmentByID(department.id);
            }
            //fields validation
            if (String.IsNullOrEmpty(ui_deptcode_textbox.Text) || String.IsNullOrEmpty(ui_deptname_textbox.Text)
                || (Convert.ToInt32(ui_collectionpoint_dropdown.SelectedValue) < 1))
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Field(s) marked with * can't be empty.") { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" });
                return;
            }

            //setting up object
            //user.username = ui_username_textbox.Text;

            department.code = ui_deptcode_textbox.Text;
            department.department_name = ui_deptname_textbox.Text;
            department.contact_name = ui_contactname_textbox.Text;
            department.phone = ui_phone_textbox.Text;
            department.representative_name = ui_representativename_textbox.Text;
            try {
                int head_id = Convert.ToInt32(ui_depthead_dropdown.SelectedValue);
                if (head_id > 0)
                {
                    department.department_head = head_id;
                }
            } catch (Exception ex){
                department.department_head = null;
            }

            int collection_point = Convert.ToInt32(ui_collectionpoint_dropdown.SelectedValue);
            if (collection_point > 0)
            {
                department.collection_point = collection_point;
            }

            //updating db;
            Message message;
            if (department.id > 0)
            {
                message = departmentController.actionUpdateDepartment(department);
            }
            else
            {
                message = departmentController.actionCreateDepartment(department);
            }

            //redirecting
            if (message.condition)
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Successfully Saved.") { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-success") { Path = "/" });
                Response.Redirect("~/StoreClerk/DepartmentDetails.aspx?id=" + department.id);
            }
            else
            {
                Response.Cookies.Add(new HttpCookie("flash_message", message.message) { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" });
                Response.Redirect("~/StoreClerk/DepartmentDetails.aspx?id=" + department.id);
            }
        }