Beispiel #1
0
        public async Task <ActionResult <CompanyAirports> > PutCompanyAirports([FromBody] CompanyAirports companyAirports,
                                                                               [FromHeader(Name = "Authorization")] string inputToken,
                                                                               [FromRoute] int id)
        {
            if (tokenCheck.TokenChecking(inputToken))
            {
                if (id == companyAirports.Id)
                {
                    if (permissionCheck.IsAllowed(inputToken, "root"))
                    {
                        var oldCompanyAirports = await _context.CompanyAirportsSet.FindAsync(id);

                        if (oldCompanyAirports == null)
                        {
                            throw new ArgumentNullException();
                        }

                        companyAirports.CreatedAt = oldCompanyAirports.CreatedAt;
                        _context.Entry(oldCompanyAirports).State = EntityState.Detached;

                        _context.CompanyAirportsSet.Update(companyAirports);
                        await _context.SaveChangesAsync();

                        _context.Entry(companyAirports).State = EntityState.Detached;
                        return(await _context.CompanyAirportsSet
                               .Include(x => x.Company)
                               .Where(x => x.Id == id)
                               .FirstAsync());
                    }
                }
            }
            throw new ArgumentNullException();
        }
Beispiel #2
0
        public async Task <ActionResult <CompanyAirports> > PostCompanyAirports([FromBody] CompanyAirports companyAirports, [FromHeader(Name = "Authorization")] string inputToken)
        {
            if (tokenCheck.TokenChecking(inputToken))
            {
                if (companyAirports != null)
                {
                    if (permissionCheck.IsAllowed(inputToken, "root"))
                    {
                        _context.CompanyAirportsSet.Add(companyAirports);
                        await _context.SaveChangesAsync();

                        _context.Entry(companyAirports).State = EntityState.Detached;

                        return(await _context.CompanyAirportsSet
                               .Include(x => x.Company)
                               .Where(x => x.Id == companyAirports.Id)
                               .FirstAsync());
                    }
                }
            }
            throw new ArgumentNullException();
        }