public EmployeeController(IConfiguration configuration, IRequestClient <Message> requestClient)
 {
     _configuration = configuration;
     ProjectTestWrapper.SetBaseUrl(_configuration["BackEndBaseUrl"]);
     //ProjectTestWrapper.SetToken(HttpContext.Session.GetString("Token"));
     _requestClient = requestClient;
 }
        // GET: Departments/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Token")))
            {
                return(RedirectToAction("Login", "Security"));
            }
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                ProjectTestWrapper.SetToken(HttpContext.Session.GetString("Token"));
                var obj = ProjectTestWrapper.Get <EmployeeViewModel>("/api/Employees/" + id);
                return(View(obj));
            }
            catch (UnauthorizedAccessException ex)
            {
                return(Unauthorized());
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
 public async Task <IActionResult> Create([Bind("UserId,EmployeeName,ClockIn,ClockOut,Active")] EmployeeViewModel employee)
 {
     try
     {
         ProjectTestWrapper.SetToken(HttpContext.Session.GetString("Token"));
         var obj = ProjectTestWrapper.Post <EmployeeViewModel>("/api/Employees", employee);
         return(RedirectToAction("Index", "Employee"));
     }
     catch (UnauthorizedAccessException ex)
     {
         return(Unauthorized());
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         return(View(employee));
     }
 }
 public async Task <IActionResult> Delete(EmployeeViewModel employee)
 {
     try
     {
         ProjectTestWrapper.SetToken(HttpContext.Session.GetString("Token"));
         var obj = ProjectTestWrapper.Delete <dynamic>("/api/Employees/" + employee.UserID);
         return(RedirectToAction("Index", "Employee"));
     }
     catch (UnauthorizedAccessException ex)
     {
         return(Unauthorized());
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         return(View(employee));
     }
 }
 // GET: Departments/Details/5
 public async Task <IActionResult> Details(int?id)
 {
     if (id == null)
     {
         return(NotFound());
     }
     try
     {
         ProjectTestWrapper.SetToken(HttpContext.Session.GetString("Token"));
         var obj = ProjectTestWrapper.Get <EmployeeViewModel>("/api/Employees/" + id);
         return(View(obj));
     }
     catch (UnauthorizedAccessException ex)
     {
         return(Unauthorized());
     }
     catch (Exception ex)
     {
         return(NotFound());
     }
 }
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string token = "";

                    var obj = ProjectTestWrapper.Post <dynamic>("/api/login", model, isToken: true);
                    token = obj.access_token;
                    HttpContext.Session.SetString("Token", token);
                    return(RedirectToAction("Index", "Employee"));
                }
                ModelState.AddModelError("", "Invalid login attempt");
                return(View(model));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Invalid login attempt");
                return(View(model));
            }
        }
 // GET: Departments
 public async Task <IActionResult> Index()
 {
     if (string.IsNullOrEmpty(HttpContext.Session.GetString("Token")))
     {
         return(RedirectToAction("Login", "Security"));
     }
     try
     {
         ProjectTestWrapper.SetToken(HttpContext.Session.GetString("Token"));
         var obj = ProjectTestWrapper.Get <IList <EmployeeViewModel> >("/api/Employees");
         return(View(obj));
     }
     catch (UnauthorizedAccessException ex)
     {
         return(Unauthorized());
     }
     catch (Exception ex)
     {
         var schoolContext = new List <EmployeeViewModel>();
         return(View(schoolContext));
     }
 }
 public SecurityController(IConfiguration Configuration)
 {
     _configuration = Configuration;
     ProjectTestWrapper.SetBaseUrl(_configuration["BackEndBaseUrl"]);
 }