Beispiel #1
0
        public async Task <Company> UpdateCompanyAsync(int companyid, CompanyRequest companyrequest)
        {
            var dbcompanys = await _context.Companys.Where(p => p.Name == companyrequest.Name && p.Id != companyid).ToArrayAsync();

            if (dbcompanys.Length > 0)
            {
                throw new RequestedResourceHasConflictException("code");
            }

            dbcompanys = _context.Companys.Where(p => p.Id == companyid).ToArray();
            if (dbcompanys.Length == 0)
            {
                throw new RequestedResourceNotFoundException();
            }

            var dbcompany = dbcompanys[0];

            dbcompany.Name    = companyrequest.Name;
            dbcompany.Address = companyrequest.Address;
            dbcompany.City    = companyrequest.City;
            dbcompany.Country = companyrequest.Country;
            await _context.SaveChangesAsync();

            return(dbcompany);
        }
Beispiel #2
0
        public async Task <Company> CreateCompanyAsync(CompanyRequest companyrequest)
        {
            var dbcompany = await _context.Companys.Where(h => (h.Name == companyrequest.Name && h.City == companyrequest.Name)).ToArrayAsync();

            if (dbcompany.Length > 0)
            {
                throw new RequestedResourceHasConflictException("code");
            }

            var company = Mapper.Map <CompanyRequest, Company>(companyrequest);

            _context.Companys.Add(company);

            await _context.SaveChangesAsync();

            return(company);
        }