コード例 #1
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));
     }
 }
コード例 #2
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));
            }
        }