Пример #1
0
        public IActionResult AddHistoricalPositions([FromBody] HistoricPositionsDTO positions)
        {
            if (positions == null || positions.Name == null || positions.Positions == null)
            {
                throw new ArgumentNullException(nameof(positions));
            }
            if (positionRepository.AddPositions(positions))
            {
                return(Ok());
            }

            return(BadRequest());
        }
 public bool AddPositions(HistoricPositionsDTO positions)
 {
     try
     {
         foreach (var position in positions.Positions)
         {
             Position p = new Position {
                 Name = positions.Name, Longitude = position.Longitude, Latitude = position.Latitude, Time = position.Time
             };
             context.Positions.Add(p);
         }
         context.SaveChanges();
         return(true);
     }catch (Exception e)
     {
         return(false);
     }
 }