/// <summary> /// This method is used to delete oraganisation information based on key parameters /// </summary> /// <param name="oraganisation"></param> /// <param name="key"></param> public void DeleteOraganisation(Oraganisation oraganisation, CommonEnums.SearchKey key) { try { DataContext dataContext = new DataContext(); Oraganisation resOraganisation = new Oraganisation(); switch (key) { case CommonEnums.SearchKey.OraganisationId: { resOraganisation = dataContext.Oraganisations.Find(oraganisation.Id); break; } case CommonEnums.SearchKey.OraganisationName: { resOraganisation = dataContext.Oraganisations.Find(oraganisation.Name); break; } case CommonEnums.SearchKey.RegistrationNumber: { resOraganisation = dataContext.Oraganisations.Find(oraganisation.RegistrationNumber); break; } } dataContext.Oraganisations.Remove(resOraganisation); dataContext.SaveChanges(); } catch (Exception exception) { throw exception; } }
/// <summary> /// This method is used to search list of oraganisations based on different parameters /// </summary> /// <param name="oraganisation"></param> /// <param name="key"></param> /// <returns></returns> public List <Oraganisation> SearchOraganisations(Oraganisation oraganisation, CommonEnums.SearchKey key) { List <Oraganisation> resOraganisations = null; DataContext dataContext = new DataContext(); try { switch (key) { case CommonEnums.SearchKey.SuburbId: { resOraganisations = dataContext.Oraganisations.Where(o => o.SuburbId == oraganisation.SuburbId) .ToList <Oraganisation>(); break; } } } catch (Exception exception) { throw exception; } return(resOraganisations); }
/// <summary> /// This method is used to add new oraganisation information /// </summary> /// <param name="oraganisation"></param> public void InsertOraganisation(Oraganisation oraganisation) { try { DataContext dataContext = new DataContext(); dataContext.Oraganisations.Add(oraganisation); dataContext.SaveChanges(); } catch (Exception exception) { throw exception; } }
/// <summary> /// This method is used to update details of oraganisation /// </summary> /// <param name="oraganisation"></param> public void UpdateOraganisation(Oraganisation oraganisation) { try { DataContext dataContext = new DataContext(); Oraganisation resOraganisation = dataContext.Oraganisations.Where(o => o.Id == oraganisation.Id).Select(o => o as Oraganisation).FirstOrDefault(); if (resOraganisation != null) { resOraganisation.Name = oraganisation.Name; dataContext.Entry(resOraganisation).State = EntityState.Modified; dataContext.SaveChanges(); } } catch (Exception exception) { throw exception; } }