public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutCompany(int id, Company company)
        {
            if (id != company.Id)
            {
                return(BadRequest());
            }


//            _context.Entry(company).State = EntityState.Modified;
            var entityCompany = _context.Companies
                                .Include(c => c.Category)
                                .Include(c => c.Owner)
//                                        .Include(c => c.Services)
                                .FirstOrDefault(c => c.Id == id);

            if (entityCompany == null)
            {
                return(NotFound(new { text = "Company with this id not found" }));
            }

            var category = _context.Categories.FirstOrDefault(c => c.Id == company.Category.Id);

            if (category == null)
            {
                return(NotFound(new { text = "Category with this id not found" }));
            }

            entityCompany.Category    = category;
            entityCompany.Name        = company.Name;
            entityCompany.Website     = company.Website;
            entityCompany.Email       = company.Email;
            entityCompany.Phone       = company.Phone;
            entityCompany.Location    = company.Location;
            entityCompany.Description = company.Description;
            entityCompany.Services    = company.Services;


            _context.Companies.Update(entityCompany);


//            _context.Services.Remove(company);
//            await _context.SaveChangesAsync();

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompanyExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(CreatedAtAction(nameof(GetCompany), new { id = company.Id }, entityCompany));
        }
        public async Task <ActionResult <Account> > Register(Account accData)
        {
            var account = accData;
            var user    = account.Owner;

            _context.Users.Add(user);

            _context.Accounts.Add(account);
            await _context.SaveChangesAsync();

            return(Ok());
        }