예제 #1
0
        public JsonResult Get(int employeeId)
        {
            try
            {
                var result = _repository.GetEmployeeById(employeeId);

                var matchingNurs = User.FindAll("Nursery").FirstOrDefault(claim => claim.Value == result.NurseryId.ToString());
                if (User.IsInRole("Admin") || matchingNurs != null)
                {
                    if (result == null)
                    {
                        return(Json(null));
                    }

                    return(Json(Mapper.Map <EmployeeViewModel>(result)));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to get class {employeeId}", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Error occurred finding class id"));
            }

            Response.StatusCode = (int)HttpStatusCode.Unauthorized;
            return(Json("Unauthorized to view this employee"));
        }