public IActionResult AddDepartment([FromBody] Department department)
 {
     if (department.GpsPoint != null)
     {
         _dbContext.GpsPoints.Add(department.GpsPoint);
     }
     _dbContext.Departments.Add(department);
     _dbContext.SaveChanges();
     return(Json(department));
 }
 public IActionResult AddFireCar([FromBody] FireCar fireCar)
 {
     fireCar.Department = _dbContext.Departments.FirstOrDefault(d => d.Id == fireCar.Department.Id);
     if (fireCar.GpsPoint != null)
     {
         _dbContext.GpsPoints.Add(fireCar.GpsPoint);
     }
     _dbContext.FireCars.Add(fireCar);
     _dbContext.SaveChanges();
     return(Json(fireCar));
 }
Beispiel #3
0
 public IActionResult AddHydrant([FromBody] Hydrant hydrant)
 {
     if (hydrant.GpsPoint == null)
     {
         hydrant.GpsPoint = new GpsPoint();
     }
     _dbContext.GpsPoints.Add(hydrant.GpsPoint);
     _dbContext.Hydrants.Add(hydrant);
     _dbContext.SaveChanges();
     return(Json(hydrant));
 }
        public IActionResult DeleteAddress(int id)
        {
            var address = _dbContext.Addresses.FirstOrDefault(a => a.Id == id);

            if (address == null)
            {
                return(NotFound());
            }
            _dbContext.Addresses.Remove(address);
            _dbContext.SaveChanges();
            return(Ok());
        }
 public IActionResult AddDeparture([FromBody] Departure dep)
 {
     dep.History  = new List <HistoryRecord>();
     dep.FireCars = new List <FireCar>();
     dep.Images   = new List <Image>();
     dep.Operator = null;
     if (dep.GpsPoint != null)
     {
         _dbContext.GpsPoints.Add(dep.GpsPoint);
     }
     _dbContext.Departures.Add(dep);
     _dbContext.SaveChanges();
     return(Json(dep));
 }
        public IActionResult UpdateLocation(int idCar, [FromBody] GpsPoint gpsPoint)
        {
            var car = _dbContext.FireCars.FirstOrDefault(c => c.Id == idCar);

            if (car == null)
            {
                return(NotFound("Car not found."));
            }
            _dbContext.GpsPoints.Load();
            car.GpsPoint.Lat   = gpsPoint.Lat;
            car.GpsPoint.Lon   = gpsPoint.Lon;
            car.LastUpdateTime = DateTime.Now;
            _dbContext.SaveChanges();
            return(Ok());
        }
Beispiel #7
0
 public IActionResult AddFire([FromBody] Fire fire)
 {
     if (fire.Department != null)
     {
         fire.Department = _dbContext.Departments.FirstOrDefault(d => d.Id == fire.Department.Id);
     }
     fire.History  = new List <HistoryRecord>();
     fire.FireCars = new List <FireCar>();
     fire.Images   = new List <Image>();
     //fire.Operator = _dbContext.Operators.FirstOrDefault(o => fire.Operator.Id == o.Id);
     //TODO: ������� ����������� ��������� �� ������
     fire.Operator = null;
     if (fire.GpsPoint != null)
     {
         _dbContext.GpsPoints.Add(fire.GpsPoint);
     }
     _dbContext.Fires.Add(fire);
     _dbContext.SaveChanges();
     return(Json(fire));
 }
        private Operator Authenticate(LoginModel login)
        {
            //Если вообще никого нет в БД, то делаем нового юзера
            if (!_dbContext.Operators.Any())
            {
                _dbContext.Operators.Add(new Operator()
                {
                    Active  = true,
                    Login   = "******",
                    Name    = "Admin",
                    Role    = "Admin",
                    Key     = "fireman",
                    GeoZone = new GpsPoint()
                });
                _dbContext.SaveChanges();
            }

            Operator user = _dbContext.Operators.FirstOrDefault(o => o.Login == login.Username && o.Key == login.Password && o.Active);

            return(user);
        }
Beispiel #9
0
 public IActionResult AddOperator([FromBody] Operator op)
 {
     _dbContext.Operators.Add(op);
     _dbContext.SaveChanges();
     return(Json(op));
 }