//update exist method public int updateExistLicenceDB(licence licence, int licence_id) { int flag = 0; try { var updateResult = db.licences.Where(l => l.licence_callsign.Equals(licence.licence_callsign) && l.licence_status == 1).FirstOrDefault(); //Update license Date from and Date to using adding new license record if (updateResult != null) { db.licences.Add(licence); db.SaveChanges(); flag = 1; } licence existLicence = db.licences.Where(l => l.vessel_id == licence.vessel_id && l.licence_id == licence_id && l.licence_status == 1).FirstOrDefault(); //The previous license status will change to '0' using 'license_id' to avoid displaying two or more license for one vessel if (existLicence != null) { existLicence.licence_status = 0; db.licences.Attach(existLicence); db.Entry(existLicence).State = EntityState.Modified; db.SaveChanges(); flag = flag + 1; //Controller will return '2' as int value to prove that the license status has been change to '0' } } catch (Exception) { throw; } return(flag); }
//update method public int updateDistressDB(int id, distress distress) { int flag = 0; try { var result = db.distresses.Where(d => d.distress_id == id && d.distress_status == 1).FirstOrDefault(); if (result != null) { db.Entry(result).State = EntityState.Detached; db.Entry(distress).State = EntityState.Modified; flag = db.SaveChanges(); } } catch (Exception) { throw; } return(flag); }
//update method public int updateUserDB(int id, user user) { try { int flag = 0; var result = db.users.Where(u => u.user_id == id && u.user_status == 1).FirstOrDefault(); if (result != null) { db.Entry(result).State = EntityState.Detached; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); flag = 1; } return(flag); } catch (Exception) { throw; } }
//update method public int updateRadioStationDB(int id, radio_station radio_station) { int flag = 0; try { var result = db.radio_station.Where(r => r.mcs_id == id && r.mcs_status == 1).FirstOrDefault(); if (result != null) { db.Entry(result).State = EntityState.Detached; db.Entry(radio_station).State = EntityState.Modified; db.SaveChanges(); flag = 1; } } catch (Exception) { throw; } return(flag); }
//update method public int updateRegistrationDB(int id, registration registration) { try { int flag = 0; registration.registration_code = registration.registration_code.ToUpper(); //search fuction in views only accept Capital letters for vessel Registration var result = db.registrations.Where(r => r.registration_id == id && r.registration_status == 1).FirstOrDefault(); if (result != null) { db.Entry(result).State = EntityState.Detached; db.Entry(registration).State = EntityState.Modified; db.SaveChanges(); flag = 1; } return(flag); } catch (Exception) { throw; } }
//update method public int updateOwnerDB(int id, owner owner) { int flag = 0; try { var result = db.owners.Where(v => v.owner_id == id).FirstOrDefault(); if (result != null) { db.Entry(result).State = EntityState.Detached; db.Entry(owner).State = EntityState.Modified; db.SaveChanges(); flag = 1; } } catch (Exception) { throw; } return(flag); }
//update method public int updateDistrictDB(int id, district district) { try { int flag = 0; district.district_code = district.district_code.ToUpper(); //search funtion in views only accept captal for District code var result = db.districts.Where(d => d.district_id == id && d.district_status == 1).FirstOrDefault(); if (result != null) { db.Entry(result).State = EntityState.Detached; db.Entry(district).State = EntityState.Modified; db.SaveChanges(); flag = 1; } return(flag); } catch (Exception) { throw; } }