Esempio n. 1
0
        public ActionResult Login(VM_RegistrationModel registrationModel)
        {
            var loginTask = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri("https://localhost:44373/API/Accounts"),
                Content    = new StringContent(JsonConvert.SerializeObject(registrationModel), Encoding.UTF8, "application/json")
            };

            var response = client.SendAsync(loginTask);
            var result   = response.Result;

            if (result.IsSuccessStatusCode)
            {
                IEnumerable <Employee> employees = PopulateEmployees();
                var id = employees.Where(a => a.EmployeeEmail == registrationModel.EmployeeEmail).FirstOrDefault().EmployeeID;

                return(RedirectToAction("../Employees/Details/" + id));
            }
            else
            {
                RedirectToAction("../Accounts/Failed", new { sc = (int)result.StatusCode });
            }

            return(View());
        }
Esempio n. 2
0
        public IHttpActionResult Post(VM_RegistrationModel registrationModel)
        {
            var employees = employeeRepository.Get();
            var accounts  = accountRepository.Get();

            var record = employees
                         .Join(accounts, emp => emp.EmployeeID,
                               acc => acc.AccountID,
                               (emp, acc) => new
            {
                emp.EmployeeID,
                emp.EmployeeEmail,
                acc.AccountPassword,
            }
                               ).ToList();

            var user = record.FirstOrDefault(r => r.EmployeeEmail == registrationModel.EmployeeEmail &&
                                             r.AccountPassword == registrationModel.AccountPassword);

            if (user != null)
            {
                return(Ok("Berhasil!"));
            }
            else
            {
                return(BadRequest("Account not exist!"));
            }
        }
Esempio n. 3
0
        public ActionResult UpdatePassword(int id)
        {
            VM_RegistrationModel registrationModel = new VM_RegistrationModel
            {
                EmployeeID = id
            };

            return(View(registrationModel));
        }
Esempio n. 4
0
 public IHttpActionResult Post(VM_RegistrationModel registrationModel)
 {
     employeeRepository.Create(registrationModel);
     try
     {
         return(Ok());
     }
     catch
     {
         //return Content(HttpStatusCode.BadRequest, "Failed to Create Supplier");
         return(BadRequest("Failed to Add User"));
     }
 }
        public int Create(VM_RegistrationModel registrationModel)
        {
            //throw new NotImplementedException();
            var spName = "SP_InsertUser";

            parameters.Add("@EmployeeName", registrationModel.EmployeeName);
            parameters.Add("@EmployeePhone", registrationModel.EmployeePhone);
            parameters.Add("@EmployeeEmail", registrationModel.EmployeeEmail);
            parameters.Add("@AccountPassword", registrationModel.AccountPassword);

            var result = connection.Execute(spName, parameters, commandType: CommandType.StoredProcedure);

            return(result);
        }
        public ActionResult Registration(VM_RegistrationModel registrationModel)
        {
            //tdk usah savechanges, nt d lempar ke API
            HttpResponseMessage response = client.PostAsJsonAsync("Employees", registrationModel).Result;

            if (response.IsSuccessStatusCode)
            {
                return(RedirectToAction("../Accounts/Login"));
            }
            else
            {
                RedirectToAction("../Employees/Failed", new { sc = (int)response.StatusCode });
            }

            //return View();
            return(RedirectToAction("Index"));
        }
Esempio n. 7
0
        public ActionResult UpdatePassword(VM_RegistrationModel registrationModel)
        {
            IEnumerable <Account> acc = PopulateAccounts();
            var record = acc.FirstOrDefault(a => a.AccountID == registrationModel.EmployeeID).AccountPassword.ToString();

            Account new_rm = new Account
            {
                AccountID       = registrationModel.EmployeeID,
                AccountPassword = registrationModel.AccountNewPassword
            };

            if (record == registrationModel.AccountPassword)
            {
                var Task = new HttpRequestMessage
                {
                    Method     = HttpMethod.Put,
                    RequestUri = new Uri("https://localhost:44373/API/Accounts"),
                    Content    = new StringContent(JsonConvert.SerializeObject(new_rm), Encoding.UTF8, "application/json")
                };

                var response = client.SendAsync(Task);
                var result   = response.Result;
                if (result.IsSuccessStatusCode)
                {
                    ViewBag.Message = "Password had been changed!";
                }
                else
                {
                    ViewBag.error = "Failed to changed password!";
                }
                return(RedirectToAction("../Employees/Details/" + registrationModel.EmployeeID));
            }
            else
            {
                ViewBag.error = "Your current password is incorrect!";
            }

            return(View());
        }