public bool UpdateShift(int?id, string name) { SPG.ShiftsDataTable shifts = Adapter.GetShiftByID(id.Value); if (shifts.Count() == 0) { //It is a new Product return(InsertShift(name)); } SPG.ShiftsRow shift = shifts[0]; if (string.IsNullOrEmpty(name)) { throw new ApplicationException("You must provide a Shift Name."); } object[] originalRecord = shift.ItemArray; shift.ShiftName = name; if (!(originalRecord == null)) { UpdateAuditTrail(shift, originalRecord); } int rowsAffected = Adapter.Update(shift); return(rowsAffected == 1); }
public bool InsertShift(string name) { SPG.ShiftsDataTable shifts = new SPG.ShiftsDataTable(); SPG.ShiftsRow shift = shifts.NewShiftsRow(); if (string.IsNullOrEmpty(name)) { throw new ApplicationException("You must provide a Shift Name."); } shift.ShiftName = name; shifts.AddShiftsRow(shift); int rowsAffected = Adapter.Update(shifts); return(rowsAffected == 1); }
public bool DeleteShift(int id) { SPG.ShiftsDataTable shifts = Adapter.GetShiftByID(id); int rowsAffected = 0; if (shifts.Count() == 1) { SPG.ShiftsRow shift = (SPG.ShiftsRow)shifts.Rows[0]; if ((new ProductionBLL()).GetProductionByShift(id).Count != 0) { MessageBox.Show("You can't delete this shift there are other records associated to it"); return(true); } rowsAffected = Adapter.Delete(id, shift.ts); } //Return true if precisely one row was deleted, otherwise return false. return(rowsAffected == 1); }