コード例 #1
0
        public IActionResult RemoveEmployee(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "EmployeeFunctionApi/{id:int}")] HttpRequestMessage req, int id, ExecutionContext context)
        {
            /*Validate JWT*/
            if ((SecurityJwt.ValidateTokenWithRoleAsync(req.Headers.Authorization, context.FunctionAppDirectory, "Admin")) == null)
            {
                return(new UnauthorizedResult());
            }
            /*Code*/
            var         result          = db.DeleteEmployee(id);
            EmployeeDto responseMessage = _mapper.Map <Employees, EmployeeDto>(result);

            return(new OkObjectResult(responseMessage));
        }
コード例 #2
0
        public IActionResult GetServicesEmployee(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "ServiceEmployeeFunctionApi")] HttpRequestMessage req, ExecutionContext context)
        {
            /*Validate JWT*/
            if ((SecurityJwt.ValidateTokenWithRoleAsync(req.Headers.Authorization, context.FunctionAppDirectory, "Admin")) == null)
            {
                return(new UnauthorizedResult());
            }
            /*Code*/
            List <ServicesEmployees>  servicesEmployees = db.GetAllServicesEmployees();
            List <ServiceEmployeeDto> responseMessage   = _mapper.Map <List <ServicesEmployees>, List <ServiceEmployeeDto> >(servicesEmployees);

            return(new OkObjectResult(responseMessage));
        }
コード例 #3
0
        public async Task <IActionResult> UpdateEmployee(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "EmployeeFunctionApi/{id:int}")] HttpRequestMessage req, int id, ExecutionContext context)
        {
            /*Validate JWT*/
            if ((SecurityJwt.ValidateTokenWithRoleAsync(req.Headers.Authorization, context.FunctionAppDirectory, "Admin")) == null)
            {
                return(new UnauthorizedResult());
            }
            /*Code*/
            var content = await req.Content.ReadAsStringAsync();

            EmployeeDto employeeDto     = JsonSerializer.Deserialize <EmployeeDto>(content);
            Employees   employeeDb      = _mapper.Map <EmployeeDto, Employees>(employeeDto);
            var         result          = db.UpdateEmployee(employeeDb);
            EmployeeDto responseMessage = _mapper.Map <Employees, EmployeeDto>(result);

            return(new OkObjectResult(responseMessage));
        }
コード例 #4
0
        public async Task <IActionResult> AddService(
            [HttpTrigger(AuthorizationLevel.Function, "Post", Route = "ServiceFunctionApi")] HttpRequestMessage req, ExecutionContext context)
        {
            /*Validate JWT*/
            if ((SecurityJwt.ValidateTokenWithRoleAsync(req.Headers.Authorization, context.FunctionAppDirectory, "Admin")) == null)
            {
                return(new UnauthorizedResult());
            }
            /*Code*/
            var content = await req.Content.ReadAsStringAsync();

            ServiceDto servicesDto     = JsonSerializer.Deserialize <ServiceDto>(content);
            Services   servicesDb      = _mapper.Map <ServiceDto, Services>(servicesDto);
            var        result          = db.CreateService(servicesDb);
            ServiceDto responseMessage = _mapper.Map <Services, ServiceDto>(result);

            return(new OkObjectResult(responseMessage));
        }