Esempio n. 1
0
 public List<Company> GetAllDDL()
 {
     TCRepositoryDataContext context = DataBaseUtils.GetContext();
     Company entity = new Company() { IdCompany = -1, Name = "Selecciona..." };
     List<Company> entList = new List<Company>();
     List<tbl_Companies> dbListCompanies = context.tbl_Companies.Where(c => c.IdStatus == 1).ToList();
     foreach (var drItem in dbListCompanies)
     {
         Company entItem = new Company();
         AssignDataObjectToEntity(drItem, ref entItem);
         entList.Add(entItem);
     }
     entList.Insert(0, entity);
     return entList;
 }
Esempio n. 2
0
        public List<Company> GetAll()
        {
            TCRepositoryDataContext context = DataBaseUtils.GetContext();
            List<tbl_Companies> dbListCompanies = context.tbl_Companies.ToList();

            List<Company> entList = new List<Company>();

            foreach (var drItem in dbListCompanies)
            {
                Company entItem = new Company();
                AssignDataObjectToEntity(drItem, ref entItem);
                entList.Add(entItem);
            }

            return entList;
        }
Esempio n. 3
0
        public bool Save(Company newCompany)
        {
            bool blResult = false;
            try
            {

                if (newCompany.IdCompany == 0)
                {
                    blResult = Insert(newCompany);
                }
                else
                {
                    blResult = Update(newCompany);
                }
            }
            catch { return false; }
            return blResult;
        }
Esempio n. 4
0
 private void AssignDataObjectToEntity(tbl_Companies dbCompany, ref Company entCompany)
 {
     entCompany.IdCompany = dbCompany.IdCompany;
     entCompany.Name = dbCompany.Name;
     entCompany.Description = dbCompany.Description;
     entCompany.EntStatus = new Status() {
         IdStatus= dbCompany.tbl_Status.IdStatus,
         Name= dbCompany.tbl_Status.Name};
 }
Esempio n. 5
0
        private bool Update(Company entCompany)
        {
            TCRepositoryDataContext context = DataBaseUtils.GetContext();
            tbl_Companies dbCompany = context.tbl_Companies.Where(c => c.IdCompany == entCompany.IdCompany).FirstOrDefault();

            if (dbCompany != null)
            {
                try
                {
                    dbCompany.Name = entCompany.Name;
                    dbCompany.Description = entCompany.Description;
                    dbCompany.IdStatus = entCompany.EntStatus.IdStatus;
                    context.SubmitChanges();
                    return true;
                }
                catch {
                    return false;
                }
            }
            return false;
        }
Esempio n. 6
0
 private bool Insert(Company entCompany)
 {
     TCRepositoryDataContext context = DataBaseUtils.GetContext();
     tbl_Companies dbCompany = new tbl_Companies() {
         Description = entCompany.Description,
         Name = entCompany.Name,
         IdStatus = entCompany.EntStatus.IdStatus
     };
     try
     {
         context.tbl_Companies.InsertOnSubmit(dbCompany);
         context.SubmitChanges();
         return true;
     }
     catch {
         return false;
     }
 }