コード例 #1
0
 public EmployeeController(IConfiguration configuration, IRequestClient <Message> requestClient)
 {
     _configuration = configuration;
     ProjectTestWrapper.SetBaseUrl(_configuration["BackEndBaseUrl"]);
     //ProjectTestWrapper.SetToken(HttpContext.Session.GetString("Token"));
     _requestClient = requestClient;
 }
コード例 #2
0
        // 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());
            }
        }
コード例 #3
0
 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));
     }
 }
コード例 #4
0
 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));
     }
 }
コード例 #5
0
 // 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());
     }
 }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
 // 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));
     }
 }
コード例 #8
0
 public SecurityController(IConfiguration Configuration)
 {
     _configuration = Configuration;
     ProjectTestWrapper.SetBaseUrl(_configuration["BackEndBaseUrl"]);
 }