Пример #1
0
        public async Task <ActionResult <TbUserCompany> > PostTbUserCompany(TbUserCompany tbUserCompany)
        {
            if (TbUserCompanyExists(tbUserCompany.UserId, tbUserCompany.CompanyId))
            {
                return(Conflict());
            }

            _context.TbUserCompanies.Add(tbUserCompany);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (TbUserCompanyExists(tbUserCompany.UserId, tbUserCompany.CompanyId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetTbUserCompany", new { id = tbUserCompany.UserId }, tbUserCompany));
        }
Пример #2
0
        public async Task <IActionResult> PutTbUserCompany(int id, TbUserCompany tbUserCompany)
        {
            if (id != tbUserCompany.Id)
            {
                return(BadRequest());
            }

            //if (TbUserCompanyExists(tbUserCompany.UserId, tbUserCompany.CompanyId))
            //{
            //  return Conflict();
            //}

            _context.Entry(tbUserCompany).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TbUserCompanyExists(tbUserCompany.UserId, tbUserCompany.CompanyId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }