コード例 #1
0
        public async Task <PoliceStation> SavePoliceStation(PoliceStation policeStation)
        {
            if (policeStation.Id == 0)
            {
                _context.PoliceStation.Add(policeStation);
            }
            else
            {
                PoliceStation pol = _context.PoliceStation.Find(policeStation.Id);

                if (pol != null)
                {
                    //Update that PoliceStation
                    pol.PoliceStationName = policeStation.PoliceStationName;
                    pol.DistrictId        = policeStation.DistrictId;
                    _context.PoliceStation.Update(pol);
                }
            }
            try
            {
                await _context.SaveChangesAsync();

                return(policeStation);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public async Task <PoliceStation> DeletePoliceStation(int id)
        {
            PoliceStation pol = _context.PoliceStation.Find(id);

            if (pol != null)
            {
                _context.PoliceStation.Remove(pol);
            }
            try
            {
                await _context.SaveChangesAsync();

                return(pol);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }