public Barangay AddBarangay(Barangay barangay) { try { int operationType = Convert.ToInt32(barangay.BarangayId == 0 ? OperationType.Insert : OperationType.Update); using (IDbConnection con = new SqlConnection(AppSettings.ConnectionStrings)) { if (con.State == ConnectionState.Closed) { con.Open(); } var oBarangay = con.Query <Barangay>("sp_Barangay", _barangay.SetParameters(barangay, operationType), commandType: CommandType.StoredProcedure); if (oBarangay != null && oBarangay.Count() > 0) { _barangay = oBarangay.FirstOrDefault(); } } } catch (Exception ex) { _psgc.Message = ex.Message; } return(_barangay); }
public Barangay GetBarangay(int baranggayId) { _barangay = new Barangay() { BarangayId = baranggayId }; try { int operationType = Convert.ToInt32(OperationType.SelectSpecific); using (IDbConnection con = new SqlConnection(AppSettings.ConnectionStrings)) { if (con.State == ConnectionState.Closed) { con.Open(); } var oBarangay = con.Query <Barangay>("sp_Barangay", _barangay.SetParameters(_barangay, operationType), commandType: CommandType.StoredProcedure).ToList(); if (oBarangay != null && oBarangay.Count() > 0) { _barangay = oBarangay.SingleOrDefault(); } } } catch (Exception ex) { _psgc.Message = ex.Message; } return(_barangay); }
public string Delete(int barangayId) { string message = ""; try { _barangay = new Barangay() { BarangayId = barangayId }; using (IDbConnection con = new SqlConnection(AppSettings.ConnectionStrings)) { if (con.State == ConnectionState.Closed) { con.Open(); } var oBarangay = con.Query <Barangay>("sp_Barangay", _barangay.SetParameters(_barangay, (int)OperationType.Delete), commandType: CommandType.StoredProcedure); if (oBarangay != null && oBarangay.Count() > 0) { _barangay = oBarangay.FirstOrDefault(); message = "Data Deleted!"; } } } catch (Exception ex) { message = ex.Message; } return(message); }