Example #1
0
        public async Task <IActionResult> CreateNew([Bind("ID, Station_name, Fuel_type, Owner_type_code, Street_address, City, State, Zip")] Fuel_Stations updated)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Fuel_Stations newStation = new Fuel_Stations()
                    {
                        ID              = updated.ID,
                        Station_name    = updated.Station_name,
                        Fuel_type       = updated.Fuel_type,
                        Owner_type_code = updated.Owner_type_code,
                        Street_address  = updated.Street_address,
                        City            = updated.City,
                        State           = updated.State,
                        Zip             = updated.Zip
                    };

                    _context.Fuel_Stations.Add(newStation);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Thanks), new { message = "Thanks! The record has been added." }));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                // Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(updated));
        }
Example #2
0
        public async Task <IActionResult> Edit(string id, [Bind("Station_name, Fuel_type, Owner_type_code, Street_address, City, State, Zip")] Fuel_Stations updated)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Fuel_Stations fuelStations = _context.Fuel_Stations
                                                 .Where(p => p.ID == id)
                                                 .FirstOrDefault();
                    fuelStations.Station_name    = updated.Station_name;
                    fuelStations.Fuel_type       = updated.Fuel_type;
                    fuelStations.Owner_type_code = updated.Owner_type_code;
                    fuelStations.Street_address  = updated.Street_address;
                    fuelStations.City            = updated.City;
                    fuelStations.State           = updated.State;
                    fuelStations.Zip             = updated.Zip;

                    _context.Update(fuelStations);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Thanks), new { message = "Thanks! The record has been edited." }));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                // Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(updated));
        }
Example #3
0
        public async Task <IActionResult> Edit(string id)
        {
            Fuel_Stations fuelStation = _context.Fuel_Stations.Where(p => p.ID == id).FirstOrDefault();
            Fuel_Stations fsEdit      = new Fuel_Stations()
            {
                ID              = fuelStation.ID,
                Station_name    = fuelStation.Station_name,
                Fuel_type       = fuelStation.Fuel_type,
                Owner_type_code = fuelStation.Owner_type_code,
                Street_address  = fuelStation.Street_address,
                City            = fuelStation.City,
                State           = fuelStation.State,
                Zip             = fuelStation.Zip
            };

            return(await Task.FromResult(View(fsEdit)));
        }
Example #4
0
        public async Task <IActionResult> DeleteConfirmed(string id)
        {
            Fuel_Stations fuelStation = await _context.Fuel_Stations
                                        .Where(p => p.ID == id)
                                        .FirstOrDefaultAsync();

            if (fuelStation == null)
            {
                return(RedirectToAction(nameof(Search)));
            }

            try
            {
                _context.Fuel_Stations.Remove(fuelStation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Thanks), new { message = "Thanks! The record has been deleted." }));
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return(RedirectToAction(nameof(Delete), new { id = id, saveChangesError = true }));
            }
        }