Exemplo n.º 1
0
        public async Task <IActionResult> Login(string email, string password)
        {
            var loginModel = new Models.LoginModel()
            {
                Email    = email,
                Password = password
            };
            var content = _responseAPI.GetContent <Models.LoginModel>(loginModel);

            HttpClient client = new HttpClient();

            using (client = _responseAPI.Initial())
            {
                HttpResponseMessage rs = await client.PostAsync("api/Account/Auth", content);

                if (rs.IsSuccessStatusCode)
                {
                    var result = _responseAPI.ReadAsJsonAsync <TokenModel>(rs.Content).Result;
                    HttpContext.Session.SetString("userToken", result.Token);

                    HttpContext.Session.SetString("email", email);
                    HttpContext.Session.SetString("address", result.Address);
                    HttpContext.Session.SetString("fullName", result.FullName);
                    HttpContext.Session.SetString("imagePath", result.ImagePath);
                    HttpContext.Session.SetString("phoneNumber", result.PhoneNumber);
                    return(RedirectToAction("Index", "Home"));
                }
                return(RedirectToAction("Index", "Account", new { message = "Username and password doesn't match!!!" }));
            }
        }
Exemplo n.º 2
0
        public async Task<IActionResult> AddRole(string roleName)
        {
            HttpClient client = new HttpClient();
            string token = HttpContext.Session.GetString("userToken");
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

            RoleModel model = new RoleModel()
            {
                RoleName = roleName
            };
            var content = _responseAPI.GetContent<string>(roleName);

            HttpResponseMessage rs = await client.PostAsync(_responseAPI.APIHost + "/api/Roles", content);
            return RedirectToAction("Add", "Role");
        }
Exemplo n.º 3
0
        public async Task <IActionResult> EditProfile(string phone, string fullname, string address)
        {
            HttpClient client = new HttpClient();
            string     token  = HttpContext.Session.GetString("userToken");

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            var model = new EditUserProfileModel()
            {
                FullName    = fullname,
                PhoneNumber = phone,
                Address     = address
            };
            var content            = _responseAPI.GetContent <EditUserProfileModel>(model);
            HttpResponseMessage rs = await client.PutAsync(_responseAPI.APIHost + "api/Account/Information", content);

            if (rs.IsSuccessStatusCode)
            {
                TempData["Notify"] = "Edit Profile Successfully!";
                return(RedirectToAction("Index", "User"));
            }
            else
            {
                return(RedirectToAction("Index", "User"));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddProject(string projectId, string description, DateTime startDate, DateTime endDate)
        {
            if (string.IsNullOrEmpty(projectId))
            {
                return(RedirectToAction("Add", "Project", new { message = "Please input full information!!!" }));
            }
            if (string.IsNullOrEmpty(description))
            {
                return(RedirectToAction("Add", "Project", new { message = "Please input full information!!!" }));
            }
            HttpClient client = new HttpClient();
            string     token  = HttpContext.Session.GetString("userToken");

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            AddProjectModel model = new AddProjectModel()
            {
                Description      = description,
                EndDate          = endDate,
                ProjectCompanyId = projectId,
                StartDate        = startDate
            };

            var content = _responseAPI.GetContent <AddProjectModel>(model);

            HttpResponseMessage rs = await client.PostAsync(_responseAPI.APIHost + "api/Project", content);

            string message = "";

            if (rs.IsSuccessStatusCode)
            {
                message = "Successfully!!";
            }
            else if (rs.ReasonPhrase.Equals("Conflict"))
            {
                message = "Project exist";
            }
            else
            {
                message = "Invalid Date";
            }
            return(RedirectToAction("Add", "Project", new { message = message }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> UpdateEmp(EmployeeEditModel model)
        {
            HttpClient client = new HttpClient();
            string     token  = HttpContext.Session.GetString("userToken");

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            HttpResponseMessage rs = await client.GetAsync(_responseAPI.APIHost + "/api/Employees");

            #region Role
            rs = await client.GetAsync(_responseAPI.APIHost + "/api/Roles");

            if (rs.IsSuccessStatusCode)
            {
                var result = _responseAPI.ReadAsJsonAsync <List <BaseModel> >(rs.Content).Result;
                ViewBag.Roles = result;
            }
            #endregion
            var content = _responseAPI.GetContent <EmployeeEditModel>(model);

            HttpResponseMessage rsUpdate = await client.PutAsync(_responseAPI.APIHost + "/api/Employees", content);

            return(RedirectToAction("Index", "Employee"));
        }