public bool CreateAgency(TravelAgency agency) { bool success = true; try { using (var db = new EntryContext()) { if (db.TravelAgencies.FirstOrDefault(a => a.AgencyCode.Equals(agency.AgencyCode, StringComparison.CurrentCultureIgnoreCase)) != null) { success = false; } else { db.TravelAgencies.Add(agency); db.SaveChanges(); } } } catch (Exception ex) { success = false; Logs.Error("CreateAgency Exception : " + ex.ToString()); } return success; }
public List<object> GetBindingData() { List<object> result = null; try { using (var db = new EntryContext()) { var query = from i in db.TravelItems select new { Id = i.Id, ItemGuid = i.ItemGuid, TravelDate = i.TravelDate, ContactName = i.ContactName, Agency = i.Agency.AgencyName, Introducer = i.Introducer, Destination = i.Destination, GroupType = i.GroupType }; result = query.ToList<object>(); } } catch (Exception ex) { Logs.Error("GetBindingData Exception : " + ex.ToString()); } return result; }
public List<TravelAgency> GetAgenciesByFilter(string key, object value) { List<TravelAgency> results = null; try { results = new List<TravelAgency>(); using (var db = new EntryContext()) { switch (key) { case "Code": case "code": results = db.TravelAgencies.Include("AgencyContacts").Where(a => a.AgencyCode.Contains(value.ToString().ToLower())).ToList(); break; case "name": results = db.TravelAgencies.Include("AgencyContacts").Where(a => a.AgencyName.Contains(value.ToString())).ToList(); break; default: break; } } } catch (Exception ex) { Logs.Error("GetAgenciesByFilter Exception : " + ex.ToString()); } return results; }
public List<TravelItem> GetTravelItemsByDate(DateTime start, DateTime end) { List<TravelItem> results = null; try { using (var db = new EntryContext()) { var query = from i in db.TravelItems .Include("Peoples") .Include("Agency") .Include("Agency.AgencyContacts") .Include("Operator") .Include("Operator.AgencyContacts") .Include("Contact") .Include("Expenditure") where i.CreateDate >= start && i.CreateDate <= end select i; results = query.ToList<TravelItem>(); } } catch (Exception ex) { Logs.Error("GetTravelItemsByDate Exception:" + ex.ToString()); } return results; }
public List<TravelAgency> GetAgencies() { List<TravelAgency> results = null; try { using (var db = new EntryContext()) { results = db.TravelAgencies.ToList(); } } catch (Exception ex) { Logs.Error("GetAgencies Exception : " + ex.ToString()); } return results; }
public TravelItem GetTravelItemByItemGuid(Guid guid) { TravelItem result = null; try { using (var db = new EntryContext()) { var query = from i in db.TravelItems.Include("Agency").Include("Peoples") //a in db.TravelAgencies on i.Agency equals a where i.ItemGuid == guid select i; result = query.FirstOrDefault(); //result = db.TravelItems.Where(i => i.ItemGuid == guid).FirstOrDefault(); } } catch (Exception ex) { Logs.Error("GetTravelItemByItemGuid Exception : " + ex.ToString()); } return result; }
public bool DeleteAgencyByGuid(Guid guid) { bool success = true; try { using (var db = new EntryContext()) { var item = from a in db.TravelAgencies where a.ItemGuid == guid select a; db.TravelAgencies.Remove(item.FirstOrDefault()); db.SaveChanges(); } } catch (Exception ex) { success = false; Logs.Error("DeleteAgencyByGuid Exception : " + ex.ToString()); } return success; }
public bool UpdateAgency(TravelAgency a_agency) { bool success = true; try { using (var db = new EntryContext()) { db.Entry<TravelAgency>(a_agency).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } catch (Exception ex) { success = false; Logs.Error("UpdateAgency Exception : " + ex.ToString()); } return success; }
public bool DeleteTravelItem(Guid guid) { bool success = true; try { using (var db = new EntryContext()) { var items = from i in db.TravelItems where i.ItemGuid == guid select i; db.TravelItems.Remove(items.FirstOrDefault()); db.SaveChanges(); } } catch (Exception ex) { success = false; Logs.Error("DeleteTravelItem Exception : " + ex.ToString()); } return success; }
public bool CreateTravelItem(TravelItem item) { bool success = true; try { using (var db = new EntryContext()) { db.TravelItems.Add(item); db.SaveChanges(); } } catch (Exception ex) { success = false; Logs.Error("CreateTravelItem Exception : " + ex.ToString()); } return success; }