Beispiel #1
0
        public async Task <IActionResult> Create(
            [Bind("ID,FaaNumber,EasaNumber,TailNumber,AircraftModelID")] Aircraft aircraft)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aircraft);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateAircraftModelsDropDownList(aircraft.AircraftModelID);
            return(View(aircraft));
        }
Beispiel #2
0
        public async Task <ActionResult <Maintenance> > PostUnit(Maintenance maintenance)
        {
            try
            {
                // So you don't have to write date and time with Postman.
                maintenance.Added   = DateTime.Now;
                maintenance.Updated = DateTime.Now;

                _context.Maintenance.Add(maintenance);
                await _context.SaveChangesAsync();

                return(Content($"New unit with an ID {maintenance.Id} added successfully!"));
            }
            catch (DbUpdateException e)
            {
                return(Content($"Please take a look at your data and refer to the docs for proper names and types.\n{e.InnerException.Message}."));
            }
        }
Beispiel #3
0
        public async Task <TEntity> AddAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                await RepositoryPatternDemoContext.AddAsync(entity);

                await RepositoryPatternDemoContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                throw new Exception($"{nameof(entity)} could not be saved: {ex.Message}");
            }
        }
        public async Task <ActionResult <Maintenance> > PostMaintenance(Maintenance maintenance, string LogId)
        {
            _context.Maintenance.Add(maintenance);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (MaintenanceExists(LogId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetMaintenance", new { IdNumber = maintenance.IdNumber }, maintenance));
        }
Beispiel #5
0
 public async Task InsertAsync(Manutencao manutencao)
 {
     _context.Manutencao.Add(manutencao);
     await _context.SaveChangesAsync();
 }