Esempio n. 1
0
        public async Task <IActionResult> UpdateTrain(int id)
        {
            string jsonString;

            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                jsonString = await reader.ReadToEndAsync();
            }

            JObject jObject;

            try
            {
                jObject = JObject.Parse(jsonString);
            }
            catch (JsonReaderException) { return(BadRequest()); }

            foreach (var prop in jObject)
            {
                if (!(prop.Key == "trainName" || prop.Key == "trainNumber" || prop.Key == "type"))
                {
                    return(BadRequest());
                }
            }

            return(Ok(_train.UpdateTrain(jObject, id)));
        }