protected void ui_save_button_Click(object sender, EventArgs e) { StationeryController sationeryController = new StationeryController(); Stationery stationery = new Stationery(); int stationery_id; //getting hidden field id if (int.TryParse(ui_id_hiddenfield.Value, out stationery_id)) { stationery.id = Convert.ToInt32(ui_id_hiddenfield.Value); stationery = sationeryController.actionGetStationeryByID(stationery.id); } //fields validation if (String.IsNullOrEmpty(ui_code_textbox.Text) || String.IsNullOrEmpty(ui_name_textbox.Text) || String.IsNullOrEmpty(ui_reorderlevel_textbox.Text) || String.IsNullOrEmpty(ui_reorderquantity_textbox.Text) || String.IsNullOrEmpty(ui_uom_textbox.Text) || String.IsNullOrEmpty(ui_price_textbox.Text) ) { 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; //String idstring = (supplier.id > 0) ? ("?id="+supplier.id) : (""); //Response.Redirect("~/StoreClerk/SupplierDetail.aspx"+idstring); } try { stationery.reorder_level = Convert.ToInt32(ui_reorderlevel_textbox.Text); stationery.reorder_quantity = Convert.ToInt32(ui_reorderquantity_textbox.Text); stationery.price = Convert.ToDouble(ui_price_textbox.Text); } catch (Exception ex) { Response.Cookies.Add(new HttpCookie("flash_message", "Price Reorder Level and Reorder Quantity only allow numbers." ) { Path = "/" }); Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" }); return; } //setting up object //setting up object stationery.code = ui_code_textbox.Text; stationery.stationery_name = ui_name_textbox.Text; stationery.category = Convert.ToInt32(ui_category_dropdown.SelectedValue); stationery.reorder_level = Convert.ToInt32(ui_reorderlevel_textbox.Text); stationery.reorder_quantity = Convert.ToInt32(ui_reorderquantity_textbox.Text); stationery.unit_of_measure = ui_uom_textbox.Text; stationery.bin = ui_binnum_textbox.Text; //stationery.quantity_in_stock = Convert.ToInt32(ui_quantityinstock_label.Text); //stationery.pending_quantity_to_distribute = Convert.ToInt32(ui_pendingquantity_label.Text); if (Page.IsPostBack) { } stationery.first_supplier = Convert.ToInt32(ui_firstsupplier_dropdown.SelectedItem.Value); stationery.second_supplier = Convert.ToInt32(ui_secondsupplier_dropdown.SelectedItem.Value); stationery.third_supplier = Convert.ToInt32(ui_thirdsupplier_dropdown.SelectedItem.Value); //stationery.first_supplier = 5; //stationery.second_supplier = 4; //stationery.third_supplier = 1; //updating db; Message message; if (stationery.id > 0) { message = sationeryController.actionUpdateStationery(stationery); } else { stationery.quantity_in_stock = 0; stationery.pending_quantity_to_distribute = 0; message = sationeryController.actionCreateStationery(stationery); } //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/StatoneryDetail.aspx?id=" + stationery.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/StatoneryDetail.aspx?id=" + stationery.id); } }