/// <summary> /// Gets city from database by city id /// </summary> /// <param name="City_Id"></param> /// <returns>Returns SETUP_City object</returns> public SETUP_City Get(int city_Id) { using (eSuiteEntities db = new eSuiteEntities()) { try { return(db.SETUP_City.Include("SETUP_Company").Include("SETUP_Country").Where(d => d.City_Id == city_Id).FirstOrDefault()); } catch { return(null); } } }
/// <summary> /// Gets company from database by company id /// </summary> /// <param name="comp_Id"></param> /// <returns>Returns SETUP_Company object</returns> public SETUP_Company Get(int comp_Id) { using (eSuiteEntities db = new eSuiteEntities()) { try { return(db.SETUP_Company.Find(comp_Id)); } catch { return(null); } } }
/// <summary> /// Gets department from database by department id /// </summary> /// <param name="dep_Id"></param> /// <returns>Returns SETUP_Department object</returns> public SETUP_Department Get(int dep_Id) { using (eSuiteEntities db = new eSuiteEntities()) { try { return(db.SETUP_Department.Include("SETUP_Company").Where(d => d.Dep_Id == dep_Id).FirstOrDefault()); } catch { return(null); } } }
/// <summary> /// Gets a list of all companies from database /// </summary> /// <param name="comp_Id"></param> /// <returns>Returns a list of SETUP_Company object</returns> public List <SETUP_Company> List() { using (eSuiteEntities db = new eSuiteEntities()) { try { var companyList = db.SETUP_Company.ToList(); return(companyList.OrderBy(c => Convert.ToInt32(c.Comp_SortOrder == null ? 0 : c.Comp_SortOrder)).ToList()); } catch { return(null); } } }
/// <summary> /// Deletes company based on company id from database.... /// </summary> /// <param name="id"></param> /// <returns>Returns true if delted successfully else returns false...</returns> public bool Delete(int comp_Id) { using (eSuiteEntities db = new eSuiteEntities()) { try { db.Entry(db.SETUP_Company.Find(comp_Id)).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(true); } catch { return(false); } } }
/// <summary> /// Updates modified values of company to the database.... /// </summary> /// <param name="company"></param> /// <returns>Returns true if updated successfully else returns false.</returns> public bool Update(SETUP_Company company) { using (eSuiteEntities db = new eSuiteEntities()) { try { db.Entry(company).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(true); } catch { return(false); } } }
/// <summary> /// Adds new company to the database.... /// </summary> /// <param name="company"></param> /// <returns>Returns new company id if saved successfully else returns 0</returns> public int Add(SETUP_Company company) { using (eSuiteEntities db = new eSuiteEntities()) { try { db.Entry(company).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); return(company.Comp_Id); } catch { return(0); } } }
/// <summary> /// Adds new department to the database.... /// </summary> /// <param name="department"></param> /// <returns>Returns new department id if saved successfully else returns 0</returns> public int Add(SETUP_Department department) { using (eSuiteEntities db = new eSuiteEntities()) { try { db.Entry(department).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); return(department.Dep_Id); } catch { return(0); } } }
/// <summary> /// Gets a list of all companies from database for dropdowns /// </summary> /// <param name="comp_Id"></param> /// <returns>Returns a list of SETUP_Company object with only comp-id and description</returns> public List <SETUP_Company> Dropdown() { using (eSuiteEntities db = new eSuiteEntities()) { try { var companyList = db.SETUP_Company.ToList().Select(c => new SETUP_Company() { Comp_Id = c.Comp_Id, Comp_ShortDesc = c.Comp_ShortDesc, Comp_SortOrder = c.Comp_SortOrder }).ToList(); return(companyList.OrderBy(c => Convert.ToInt32(c.Comp_SortOrder == null ? 0 : c.Comp_SortOrder)).ToList()); } catch { return(null); } } }
/// <summary> /// Gets a list of all country / country based on company id from database /// </summary> /// <param name="comp_Id"></param> /// <returns>Returns a list of SETUP_Country object</returns> public List <SETUP_Country> List(int?comp_Id) { using (eSuiteEntities db = new eSuiteEntities()) { try { var countryList = db.SETUP_Country.Include("SETUP_Company").ToList(); if (comp_Id != null && comp_Id > 0) { countryList = countryList.Where(d => d.Comp_Id == comp_Id).ToList(); } return(countryList.OrderBy(c => Convert.ToInt32(c.Cont_SortOrder == null ? 0 : c.Cont_SortOrder)).ToList()); } catch { return(null); } } }
/// <summary> /// Gets a list of all countries from database for dropdowns /// </summary> /// <param name="comp_Id"></param> /// <returns>Returns a list of SETUP_Country object with only comp-id and description</returns> public List <SETUP_Country> Dropdown(int?comp_Id) { using (eSuiteEntities db = new eSuiteEntities()) { try { var countryList = db.SETUP_Country.ToList().Select(c => new SETUP_Country() { Comp_Id = c.Comp_Id, Cont_Id = c.Cont_Id, Cont_ShortDesc = c.Cont_ShortDesc, Cont_SortOrder = c.Cont_SortOrder }).ToList(); if (comp_Id != null && comp_Id > 0) { countryList = countryList.Where(d => d.Comp_Id == comp_Id).ToList(); } return(countryList.OrderBy(c => Convert.ToInt32(c.Cont_SortOrder == null ? 0 : c.Cont_SortOrder)).ToList()); } catch { return(null); } } }