Ejemplo n.º 1
0
        public ActionResult Add_User(TAIKHOANQUANTRI model, string rePassWord, int ROLE)
        {
            try
            {
                if (model.PassWord.CompareTo(rePassWord) == 0)
                {
                    var role = context.ROLES.Where(x => x.IDRole == ROLE).FirstOrDefault();
                    model.ROLES = new List <ROLE>();
                    model.ROLES.Add(role);
                    context.TAIKHOANQUANTRIs.Add(model);
                    context.SaveChanges();

                    return(RedirectToAction("Users"));
                }
                else
                {
                    TempData["Alert"] = "Xác nhận mật khẩu không đúng! Vui lòng thử lại!";
                    return(View());
                }
            }
            catch
            {
                TempData["Alert"] = "Username đã tồn tại! Vui lòng thử lại!";
                return(View());
            }
        }
Ejemplo n.º 2
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseAddress);
                TAIKHOANQUANTRI account = new TAIKHOANQUANTRI
                {
                    SDT     = tk.Text.Trim(),
                    MatKhau = mk.Text.Trim()
                };
                TAIKHOANQUANTRI acc = null;

                var resp = await client.PostAsJsonAsync <TAIKHOANQUANTRI>("quantri/login1", account);

                if (resp.IsSuccessStatusCode)
                {
                    acc = await resp.Content.ReadAsAsync <TAIKHOANQUANTRI>();

                    WELCOME.Text = "Hi: " + acc.HoTen;

                    if (acc.Role == 1)
                    {
                        tkqt.Visible = true;
                    }

                    panel_choice.Enabled = true;
                    LoadSanPham();
                }
                else
                {
                    MessageBox.Show("Error occured! Please try again.");
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult HoSo(TAIKHOANQUANTRI model, string NewPass, string Confirm)
        {
            var obj = context.TAIKHOANQUANTRIs.Where(x => x.UserName == model.UserName).FirstOrDefault();

            if (obj.PassWord.Contains(model.PassWord))
            {
                if (NewPass.CompareTo(Confirm) == 0)
                {
                    obj.HoTen    = model.HoTen;
                    obj.PassWord = NewPass;
                    context.SaveChanges();
                    return(RedirectToAction("Users"));
                }
                else
                {
                    TempData["Alert"] = "Xác nhận mật khẩu không đúng! Vui lòng thử lại!";
                    return(View("HoSo", obj));
                }
            }
            else
            {
                TempData["Alert"] = "Mật khẩu không đúng! Vui lòng thử lại!";
                return(View("HoSo", obj));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Edit_User(TAIKHOANQUANTRI model, int ROLE)
        {
            TAIKHOANQUANTRI obj = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44373/api/");
                var responseTask = await client.GetAsync("quantri/getTKQT/" + model.MaQT.ToString());

                if (responseTask.IsSuccessStatusCode)
                {
                    obj = await responseTask.Content.ReadAsAsync <TAIKHOANQUANTRI>();
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            obj.Role = ROLE;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44373/api/");
                var putTask = await client.PutAsJsonAsync <TAIKHOANQUANTRI>("quantri/updateTKQT", obj);

                if (!putTask.IsSuccessStatusCode)
                {
                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            return(RedirectToAction("Users"));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Add_User(TAIKHOANQUANTRI model, string reMatKhau, int ROLE)
        {
            try
            {
                if (model.MatKhau.CompareTo(reMatKhau) == 0)
                {
                    model.Role = ROLE;
                    using (var client = new HttpClient())
                    {
                        //gọi api thêm đơn hàng
                        client.BaseAddress = new Uri("https://localhost:44373/api/");
                        var responseTask = await client.PostAsJsonAsync <TAIKHOANQUANTRI>("quantri/addTKQT", model);

                        if (!responseTask.IsSuccessStatusCode)
                        {
                            ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                        }
                    }
                    return(RedirectToAction("Users"));
                }
                else
                {
                    TempData["Alert"] = "Xác nhận mật khẩu không đúng! Vui lòng thử lại!";
                    return(View());
                }
            }
            catch
            {
                TempData["Alert"] = "SDT đã tồn tại! Vui lòng thử lại!";
                return(View());
            }
        }
        public TAIKHOANQUANTRI Login1(TAIKHOANQUANTRI acc)
        {
            TAIKHOANQUANTRI ac = new TAIKHOANQUANTRI();

            using (MyDBContext context = new MyDBContext())
            {
                var result = context.TAIKHOANQUANTRIs.Where(a => a.SDT.Equals(acc.SDT) &&
                                                            a.MatKhau.Equals(acc.MatKhau)).FirstOrDefault();
                if (result != null)
                {
                    ac.MaQT    = result.MaQT;
                    ac.SDT     = result.SDT;
                    ac.MatKhau = result.MatKhau;
                    ac.HoTen   = result.HoTen;
                    ac.Role    = result.Role;
                    //foreach (ROLE it in result.ROLES)
                    //{
                    //    ac.Roles.Add(it.RoleName);
                    //}
                    return(ac);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 7
0
        public ActionResult Edit_User(TAIKHOANQUANTRI model, int ROLE)
        {
            var role = context.ROLES.Where(x => x.IDRole == ROLE).FirstOrDefault();
            var obj  = context.TAIKHOANQUANTRIs.Where(x => x.UserName == model.UserName).FirstOrDefault();

            obj.ROLES.Clear();
            obj.ROLES.Add(role);
            obj.HoTen = model.HoTen;
            //obj.IDRole = model.IDRole;
            context.SaveChanges();
            return(RedirectToAction("Users"));
        }
Ejemplo n.º 8
0
 private void them(object sender, EventArgs e)
 {
     if (condition())
     {
         TAIKHOANQUANTRI tk = new TAIKHOANQUANTRI();
         tk.HoTen   = ten.Text;
         tk.MatKhau = matkhau.Text;
         tk.SDT     = sdt.Text;
         tk.Role    = Convert.ToInt32(comboBox1.SelectedValue.ToString());
         Function.Add("quantri/addTKQT", tk);
         clear();
         loadGridview();
     }
 }
 public bool ThemQuanTri(TAIKHOANQUANTRI dc)
 {
     try
     {
         MyDBContext context = new MyDBContext();
         context.TAIKHOANQUANTRIs.Add(dc);
         context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 10
0
        public ActionResult Edit_User(int ID)
        {
            IEnumerable <ROLE> model1 = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44373/api/");
                //HTTP GET
                var responseTask = client.GetAsync("role/getlistrole");
                responseTask.Wait();
                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <IEnumerable <ROLE> >();
                    readTask.Wait();

                    model1 = readTask.Result;
                }
                else
                {
                    model1 = null;
                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            ViewBag.role = model1;

            TAIKHOANQUANTRI model = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44373/api/");
                //HTTP GET
                var responseTask = client.GetAsync("quantri/getTKQT/" + ID.ToString());
                responseTask.Wait();
                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <TAIKHOANQUANTRI>();
                    readTask.Wait();
                    model = readTask.Result;
                }
                else
                {
                    model = null;
                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            return(View(model));
        }
Ejemplo n.º 11
0
 private void sua(object sender, EventArgs e)
 {
     if (condition())
     {
         TAIKHOANQUANTRI tk = new TAIKHOANQUANTRI();
         tk.MaQT    = Convert.ToInt32(id_temp);
         tk.HoTen   = ten.Text;
         tk.MatKhau = matkhau.Text;
         tk.SDT     = sdt.Text;
         tk.Role    = Convert.ToInt32(comboBox1.SelectedValue.ToString());
         Function.Edit("quantri/updateTKQT", tk);
         AddForm();
         loadGridview();
     }
 }
Ejemplo n.º 12
0
        public async Task <ActionResult> HoSo(TAIKHOANQUANTRI model, string NewPass, string Confirm)
        {
            TAIKHOANQUANTRI obj = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44373/api/");
                var responseTask = await client.GetAsync("quantri/getTKQT/" + model.MaQT.ToString());

                if (responseTask.IsSuccessStatusCode)
                {
                    obj = await responseTask.Content.ReadAsAsync <TAIKHOANQUANTRI>();
                }
                else
                {
                    obj = null;
                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            if (obj.MatKhau.Contains(model.MatKhau))
            {
                model.MatKhau = NewPass;
                if (NewPass.CompareTo(Confirm) == 0)
                {
                    using (var client = new HttpClient())
                    {
                        var putTask = await client.PutAsJsonAsync <TAIKHOANQUANTRI>("danhmuc/updateTKQT", model);

                        if (!putTask.IsSuccessStatusCode)
                        {
                            ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                        }
                    }
                    return(RedirectToAction("Users"));
                }
                else
                {
                    TempData["Alert"] = "Xác nhận mật khẩu không đúng! Vui lòng thử lại!";
                    return(View("HoSo", obj));
                }
            }
            else
            {
                TempData["Alert"] = "Mật khẩu không đúng! Vui lòng thử lại!";
                return(View("HoSo", obj));
            }
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> HoSo(int ID)
        {
            TAIKHOANQUANTRI model = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44373/api/");
                var responseTask = await client.GetAsync("quantri/getTKQT/" + ID.ToString());

                if (responseTask.IsSuccessStatusCode)
                {
                    model = await responseTask.Content.ReadAsAsync <TAIKHOANQUANTRI>();
                }
                else
                {
                    model = null;
                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            return(View(model));
        }
 public bool UpdateQuanTri(TAIKHOANQUANTRI dc)
 {
     try
     {
         MyDBContext context = new MyDBContext();
         var         QT      = context.TAIKHOANQUANTRIs.Find(dc.MaQT);
         if (QT == null)
         {
             return(false);
         }
         else
         {
             QT.Role  = dc.Role;
             QT.HoTen = dc.HoTen;
             context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }