Esempio n. 1
0
        public static async Task <IActionResult> AddNewEngineer([HttpTrigger(AuthorizationLevel.Function, "post", Route = "engineers/")] HttpRequest req, ILogger log)
        {
            log.LogInformation($"Add new engineer request");

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

                if (_Entity.TeamID.Length > 0 && new EngineeringTeamsRepository().Get(_Entity.TeamID) == null)
                {
                    throw new Exception();
                }

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

            return(new OkResult());
        }
Esempio n. 2
0
        public static async Task <IActionResult> UpdateEngineer([HttpTrigger(AuthorizationLevel.Function, "put", Route = "engineers/{customID}")] HttpRequest req, string customID, ILogger log)
        {
            log.LogInformation($"Update existing engineer request");

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

                if (await EngineerRepo.Get(customID) != null)
                {
                    if (_Entity.TeamID.Length > 0 && new EngineeringTeamsRepository().Get(_Entity.TeamID) == null)
                    {
                        return(new BadRequestObjectResult("Please provide a valid team."));
                    }

                    await EngineerRepo.Update(customID, _Entity);
                }
                else
                {
                    return(new NotFoundResult());
                }
            }
            catch (Exception _Exception)
            {
                log.LogError(_Exception.Message);
                return(new NotFoundResult());
            }

            return(new OkResult());
        }
Esempio n. 3
0
        public static async Task <IActionResult> GetAllEngineers([HttpTrigger(AuthorizationLevel.Function, "get", Route = "engineers/")] HttpRequest req, ILogger log)
        {
            log.LogInformation("Get All Airplanes Requested");

            List <EngineerEntity> _Engineers = await EngineerRepo.Get();

            return(new JsonResult(_Engineers));
        }
Esempio n. 4
0
        public static async Task <IActionResult> GetSingleEngineer([HttpTrigger(AuthorizationLevel.Function, "get", Route = "engineers/{customID}/")] HttpRequest req, string customID, ILogger log)
        {
            log.LogInformation($"GET single engineer {customID}");

            EngineerEntity _Result = null;

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

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

            return(new JsonResult(_Result));
        }
Esempio n. 5
0
        public static async Task <IActionResult> RemoveEngineer([HttpTrigger(AuthorizationLevel.Function, "delete", Route = "engineers/{customID}")] HttpRequest req, string customID, ILogger log)
        {
            log.LogInformation($"Remove airplane request");

            try
            {
                if (await EngineerRepo.Get(customID) != null)
                {
                    await EngineerRepo.Remove(customID);
                }
                else
                {
                    return(new NotFoundResult());
                }
            }
            catch (Exception _Exception)
            {
                log.LogError(_Exception.Message);
                return(new NotFoundResult());
            }

            return(new OkResult());
        }