Example #1
0
        public static async Task <IActionResult> AddNewMaintenanceCheck([HttpTrigger(AuthorizationLevel.Function, "post", Route = "maintenance/")] HttpRequest req, ILogger log)
        {
            log.LogInformation($"Add new check request");
            MaintenanceCheckEntity _Entity = null;

            try
            {
                string _RequestBody = await new StreamReader(req.Body).ReadToEndAsync();
                _Entity = JsonConvert.DeserializeObject <MaintenanceCheckEntity>(_RequestBody);

                if (new AirplaneRepository().Get(_Entity.FlightRegNo) == null)
                {
                    return(new BadRequestObjectResult("Please provide a valid flight."));
                }

                await ChecksRepo.Create(_Entity);
            }
            catch (Exception _Exception)
            {
                log.LogError("Error in Deserializing");
                log.LogError(_Exception.Message);
                return(new BadRequestResult());
            }

            return(new OkObjectResult(_Entity));
        }
Example #2
0
        public static async Task <IActionResult> UpdateCheck([HttpTrigger(AuthorizationLevel.Function, "put", Route = "maintenance/{id}")] HttpRequest req, string id, ILogger log)
        {
            log.LogInformation($"Update existing engineer request");

            try
            {
                string _RequestBody            = await new StreamReader(req.Body).ReadToEndAsync();
                MaintenanceCheckEntity _Entity = JsonConvert.DeserializeObject <MaintenanceCheckEntity>(_RequestBody);

                if (await ChecksRepo.Get(id) != null)
                {
                    await ChecksRepo.Update(id, _Entity);
                }
                else
                {
                    return(new NotFoundResult());
                }
            }
            catch (Exception _Exception)
            {
                log.LogError(_Exception.Message);
                return(new NotFoundResult());
            }

            return(new OkResult());
        }
 public async Task Update(string id, MaintenanceCheckEntity check)
 {
     var serializerSettings = new JsonSerializerSettings()
     {
         NullValueHandling    = NullValueHandling.Ignore,
         DefaultValueHandling = DefaultValueHandling.Ignore
     };
     var bson = new BsonDocument()
     {
         { "$set", BsonDocument.Parse(JsonConvert.SerializeObject(check, serializerSettings)) }
     };
     await _MaintenanceChecksCollection.UpdateOneAsync(Builders <MaintenanceCheckEntity> .Filter.Eq(c => c.Id, id), bson);
 }
Example #4
0
        public static async Task <IActionResult> GetSingleCheck([HttpTrigger(AuthorizationLevel.Function, "get", Route = "maintenance/{id}/")] HttpRequest req, string id, ILogger log)
        {
            log.LogInformation($"GET single check {id}");

            MaintenanceCheckEntity _Result = null;

            try
            {
                _Result = await ChecksRepo.Get(id);
            }
            catch (Exception _Exception)
            {
                log.LogError(_Exception.Message);
            }

            if (_Result == null)
            {
                return(new NotFoundResult());
            }

            return(new JsonResult(_Result));
        }
 public async Task Remove(MaintenanceCheckEntity check)
 {
     await Remove(check.Id);
 }
        public async Task <MaintenanceCheckEntity> Create(MaintenanceCheckEntity maintenanceCheck)
        {
            await _MaintenanceChecksCollection.InsertOneAsync(maintenanceCheck);

            return(maintenanceCheck);
        }