コード例 #1
0
        public static async Task <IActionResult> EmployeeUpdate(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "employee")] HttpRequestMessage req,
            ILogger log)
        {
            try
            {
                string reqBody = await req.Content.ReadAsStringAsync();

                Data.Employee employee = JsonConvert.DeserializeObject <Data.Employee>(reqBody);
                log.LogInformation("Updating Employee Data to Repo");

                IEmployeeRepository empData = new EmployeeRepository();
                if (employee != null)
                {
                    var result = empData.UpdateEmployee(employee);

                    if (result)
                    {
                        return(new NoContentResult());
                    }
                    else
                    {
                        return(new BadRequestResult());
                    }
                }
                else
                {
                    return(new NotFoundObjectResult($"Not Found/Unable to update"));
                }
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex));
            }
        }
コード例 #2
0
        public static async Task <IActionResult> EmployeeInsert(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "employee")] HttpRequestMessage req,
            ILogger log)
        {
            try
            {
                string reqBody = await req.Content.ReadAsStringAsync();

                Data.Employee employee = JsonConvert.DeserializeObject <Data.Employee>(reqBody);
                log.LogInformation("Inserting Employee Data to Repo");

                IEmployeeRepository empData = new EmployeeRepository();
                if (employee != null)
                {
                    var result = empData.InsertEmployee(employee);

                    if (result)
                    {
                        return(new NoContentResult());
                    }
                    else
                    {
                        return(new BadRequestResult());
                    }
                }
                else
                {
                    return(new BadRequestObjectResult($"Unable to create employee, check if the record with same id already exists. Update if it does."));
                }
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex));
            }
        }