Beispiel #1
0
        public async Task<bool> UpdateCompany(int id, Company company)
        {
            using (db = new Diplomna_newEntities())
            {
                Company companyFromDb = await db.Companies.FindAsync(id);

                companyFromDb.AddressText = company.AddressText;
                companyFromDb.CityID = company.CityID;
                companyFromDb.CompanyName = company.CompanyName;
                companyFromDb.Email = company.Email;
                companyFromDb.Phones = company.Phones;

                db.Entry(companyFromDb).State = EntityState.Modified;

                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!(await CompanyExists(id)))
                    {
                        return false; // does not exist
                    }
                    else
                    {
                        throw;
                    }
                }

                return true;
            }
        }
Beispiel #2
0
        public async Task<List<GetCityEntity>> GetCities()
        {
            using (db = new Diplomna_newEntities())
            {
                List<GetCityEntity> cities = await db.Cities.Select(x => new GetCityEntity
                {
                    CityId = x.CityID,
                    CityName = x.CityName
                }).ToListAsync();

                return cities;
            }
        }
Beispiel #3
0
        public async Task<GetCityEntity> GetCityById(int id)
        {
            using (db = new Diplomna_newEntities())
            {
                GetCityEntity city = await db.Cities
                    .Where(x => x.CityID == id)
                    .Select(x => new GetCityEntity
                    {
                        CityId = x.CityID,
                        CityName = x.CityName
                    }).FirstOrDefaultAsync();

                return city;
            }
        }
Beispiel #4
0
        public async Task<GetCompanyByUsername> GetCompanyByUsername(string username)
        {
            using (db = new Diplomna_newEntities())
            {
                GetCompanyByUsername company = await db.Companies
                    .Where(x => x.CreateBy.ToUpper() == username.ToUpper() && !x.IsDeleted)
                    .Select(x => new GetCompanyByUsername
                    {
                        CompanyAddress = x.AddressText,
                        CityID = x.CityID,
                        CompanyID = x.CompanyID,
                        CompanyName = x.CompanyName,
                        CreateBy = x.CreateBy,
                        Email = x.Email,
                        CompanyPhones = x.Phones
                    }).FirstOrDefaultAsync();

                return company;
            }
        }
Beispiel #5
0
        public async Task<List<GetCompanyEntity>> GetCompanies()
        {
            using (db = new Diplomna_newEntities())
            {
                List<GetCompanyEntity> companies = await db.Companies.Select(x => new GetCompanyEntity
                {
                    AddedOn = x.AddedOn,
                    AddressText = x.AddressText,
                    CityID = x.CityID,
                    CompanyID = x.CompanyID,
                    CompanyName = x.CompanyName,
                    CreateBy = x.CreateBy,
                    DeletedBy = x.DeletedBy,
                    DeletedDate = x.DeletedDate,
                    Email = x.Email,
                    IsDeleted = x.IsDeleted,
                    Phones = x.Phones
                }).ToListAsync();

                return companies;
            }
        }
Beispiel #6
0
        public async Task<Company> InsertCompany(Company company)
        {
            using (db = new Diplomna_newEntities())
            {
                db.Companies.Add(company);
                await db.SaveChangesAsync();

                return company;
            }
        }