コード例 #1
0
        //[ProducesResponseType(StatusCodes.Status401Unauthorized)]
        public async Task <ActionResult <CreateResponse> > Create(Company company, [FromHeader] string authorization)
        {
            if (Authenticate.AuthenticatedUser(authorization))
            {
                string validateInfo = Validate.EstablishmentYear(company.EstablishmentYear);
                if (validateInfo == "OK")
                {
                    _context.Companies.Add(company);
                    await _context.SaveChangesAsync();

                    return(new CreateResponse {
                        Id = company.CompanyID
                    });
                    //return CreatedAtAction("GetCompany", new { id = company.CompanyID }, company);
                }
                else
                {
                    return(BadRequest(validateInfo));
                }
            }
            else
            {
                return(Unauthorized());
            }
        }
コード例 #2
0
        public async Task <IActionResult> Update(Int64 id, Company company, [FromHeader] string authorization)
        {
            if (Authenticate.AuthenticatedUser(authorization))
            {
                company.CompanyID = id;

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

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

                return(NoContent());
            }
            else
            {
                return(Unauthorized());
            }
        }
コード例 #3
0
        public async Task <ActionResult <Company> > Delete(long id, [FromHeader] string authorization)
        {
            if (Authenticate.AuthenticatedUser(authorization))
            {
                var company = await _context.Companies.FindAsync(id);

                if (company == null)
                {
                    return(NotFound());
                }

                _context.Companies.Remove(company);
                await _context.SaveChangesAsync();

                return(company);
            }
            else
            {
                return(Unauthorized());
            }
        }