public MinMaxSpeedModel GetMinMaxSpeedSpeedRegistrationNotes(DateTime date)
        {
            // Get all registration notes
            SpeedRegistrationNote[] notes = _speedNotesRepository.GetSpeedRegistrationNotes();

            // Max and min speed notes
            SpeedRegistrationNote maxSpeedNote = null, minSpeedNote = null;

            if (notes != null)
            {
                // Filter notes for a given date
                SpeedRegistrationNote[] notesForDate = notes
                                                       .Where(n => n.RegistrationTime.Date == date.Date).ToArray();

                maxSpeedNote = notesForDate.FirstOrDefault();

                minSpeedNote = maxSpeedNote;

                if (maxSpeedNote != null)
                {
                    foreach (SpeedRegistrationNote note in notesForDate)
                    {
                        if (note.Speed > maxSpeedNote.Speed)
                        {
                            maxSpeedNote = note;
                        }
                        else if (note.Speed < minSpeedNote.Speed)
                        {
                            minSpeedNote = note;
                        }
                    }
                }
            }

            // Create model and return it
            return(new MinMaxSpeedModel
            {
                MinSpeedNote = minSpeedNote,
                MaxSpeedNote = maxSpeedNote
            });
        }
        public void SaveSpeedRegistrationNote(SpeedRegistrationNote note)
        {
            string speedRegistrationNotesFilePath = ConfigurationManager.AppSettings[SPEED_REGISTRATION_NOTES_FILE_PATH_KEY];

            // Read file content
            string fileContent = File.ReadAllText(speedRegistrationNotesFilePath);

            // Deserialize array of SpeedRegistrationNote objects
            SpeedRegistrationNote[] notes = JsonConvert.DeserializeObject <SpeedRegistrationNote[]>(fileContent);

            // Add new object to the deserialized array
            List <SpeedRegistrationNote> notesList = new List <SpeedRegistrationNote>(notes)
            {
                note
            };

            // Serialize array with the added element
            String json = JsonConvert.SerializeObject(notesList.ToArray());

            // Save array in the same file
            File.WriteAllText(speedRegistrationNotesFilePath, json);
        }
Пример #3
0
        public IHttpActionResult Post(SpeedRegistrationNote model)
        {
            _speedNotesRepository.SaveSpeedRegistrationNote(model);

            return(Ok());
        }