Exemplo n.º 1
0
        public HttpResponseMessage GetByIdTaiKhoan(HttpRequestMessage request, int id)
        {
            NguoiDung nguoiDungSingler = null;

            try
            {
                nguoiDungSingler = _nguoiDungService.GetByIdTaiKhoan(id);
                if (nguoiDungSingler != null)
                {
                    Message = "Thông tin người dùng với id tài khoản: " + id;
                }
                else
                {
                    throw new DbEntityValidationException(string.Format("Không tìm kiếm được người dùng với id tài khoản {0}", id));
                }
            }
            catch (DbEntityValidationException ex)
            {
                LogException(ex);
            }
            return(GetResponseMessage(IsSuccess, Message, 1, nguoiDungSingler));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Login(HttpRequestMessage request, LoginModel login)
        {
            TaiKhoan taiKhoanSinger = null;
            var      loginSucess    = false;

            try
            {
                taiKhoanSinger = _taiKhoanService.Login(login.UserName, login.Pass);
                if (taiKhoanSinger != null)
                {
                    var idQuyen = taiKhoanSinger.IdQuyen;
                    switch (idQuyen)
                    {
                    case 1:
                        loginSucess = true;
                        break;

                    case 2:
                        var coSoThuY = _coSoThuYService.GetByIdTaiKhoan(taiKhoanSinger.IdTaiKhoan);
                        if (coSoThuY.TrangThai != null && (bool)coSoThuY.TrangThai)
                        {
                            loginSucess = true;
                        }

                        break;

                    case 3:
                        var nguoiDung = _nguoiDungService.GetByIdTaiKhoan(taiKhoanSinger.IdTaiKhoan);
                        if (nguoiDung.TrangThai != null && (bool)nguoiDung.TrangThai)
                        {
                            loginSucess = true;
                        }

                        break;

                    case 4:
                        var shop = _shopService.GetByIdTaiKhoan(taiKhoanSinger.IdTaiKhoan);
                        if (shop.TrangThai != null && (bool)shop.TrangThai && (bool)shop.PheDuyet)
                        {
                            loginSucess = true;
                        }

                        break;
                    }
                }
                else
                {
                    IsSuccess = false;
                    Message   = "Đăng nhập thất bại";
                }
                if (loginSucess)
                {
                    Message = "Thông tin tài khoản đã đăng nhập thành công";
                }
                else
                {
                    throw new DbEntityValidationException("Đăng nhập thất bại");
                }
            }
            catch (DbEntityValidationException ex)
            {
                LogException(ex);
            }
            return(GetResponseMessage(IsSuccess, Message, 1, taiKhoanSinger));
        }