public async Task <ActionResultDto> Execute(ContextDto context)
        {
            try
            {
                init();
                validate();

                var count = 0;

                var repo = new NguoiDungRepository(context);

                for (int i = 0; i < _listId.Count; i++)
                {
                    if (_listId[i] > 0 && repo.Delete(_listId[i]))
                    {
                        count++;
                    }
                }

                return(returnActionResult(HttpStatusCode.OK, count, null));
            }
            catch (FormatException ex)
            {
                return(returnActionError(HttpStatusCode.BadRequest, ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
            catch (Exception ex)
            {
                return(returnActionError(HttpStatusCode.InternalServerError, ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
        }
Beispiel #2
0
        public async Task <ActionResultDto> Execute(ContextDto context)
        {
            try
            {
                var nguoidung = new Entity.MSSQL_QLDN_MAIN.Entity.NguoiDung();
                nguoidung.MaNguoiDung  = MaNguoiDung;
                nguoidung.HoTen        = HoTen;
                nguoidung.VaiTroId     = Protector.Int(VaiTroId);
                nguoidung.NhanVienId   = Protector.Int(NhanVienId);
                nguoidung.Email        = Email;
                nguoidung.PasswordHash = HashHelper.getHashSha256(PasswordHash);
                nguoidung.DienThoai    = DienThoai;
                nguoidung.NguoiTao     = NguoiTao;
                nguoidung.NgayTaoDT    = DateTime.Now;
                nguoidung.CtrVersion   = 1;
                nguoidung.UserName     = Email;
                NguoiDungRepository repo = new NguoiDungRepository(context);
                repo.Insert(nguoidung);

                return(returnActionResult(HttpStatusCode.OK, nguoidung, null));
            }
            catch (FormatException ex)
            {
                return(returnActionError(HttpStatusCode.BadRequest, ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
            catch (Exception ex)
            {
                return(returnActionError(HttpStatusCode.InternalServerError, ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
        }
        public ActionResult ExportExcel()
        {
            try
            {
                var                  webRoot = _env.WebRootPath;
                DataTable            dt      = new DataTable();
                QuanLyCongVanContext db      = new QuanLyCongVanContext();
                var                  paht    = System.IO.Path.Combine(webRoot, "Content/TempExcel/NguoiDung.xlsx");
                Workbook             wb      = new Workbook();

                //Cell Cells = char.Parse(new Cell["A3"].ToString());
                Worksheet ws = wb.Worksheets[0];
                dt.Columns.Add("Tên tài khoản");
                dt.Columns.Add("Mật khẩu");
                dt.Columns.Add("kích hoạt");
                dt.Columns.Add("Mã nhân sự");
                List <NguoiDung> listnd = new List <NguoiDung>();
                listnd = db.NguoiDung.ToList();
                string listnds = "";
                if (listnd.Count > 0)
                {
                    listnds = String.Join(",", listnd.Select(x => x.ToString()).ToArray());
                }
                var ob   = new NguoiDungRepository();
                var data = ob.GetAll();
                foreach (NguoiDung item in data)
                {
                    dt.Rows.Add(item.TenTaiKhoan, item.MatKhau, item.KichHoat, item.MaNhanSu);
                }
                string filename   = "DanhSachNguoiDung" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".xlsx";
                string folderName = "/assets/Excel/";

                var file = System.IO.Path.Combine(webRoot + folderName + filename);
                if (!System.IO.Directory.Exists(folderName))
                {
                    System.IO.Directory.CreateDirectory(folderName);
                }
                ws.Cells.ImportDataTable(dt, false, 2, 0);
                wb.Save(file);
                return(Json(folderName + filename));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public override bool Validate()
        {
            string  newNguoiDung = ControlToValidate.Text;
            TextBox textBox      = (TextBox)ControlToValidate;

            textBox.Undo();
            string oldNguoiDung = textBox.Text;

            textBox.Text = newNguoiDung;
            NguoiDungRepository nguoiDungRepository = new NguoiDungRepository();
            NguoiDung           tenTaiKhoang        = nguoiDungRepository.FindByCondition(p => p.TenTaiKhoan.Equals(newNguoiDung) && !p.TenTaiKhoan.Equals(oldNguoiDung)).SingleOrDefault();

            if (tenTaiKhoang != null)
            {
                return(false);
            }
            return(true);
        }
Beispiel #5
0
        public async Task <dynamic> Execute(ContextDto context)
        {
            try
            {
                dynamic result = new System.Dynamic.ExpandoObject();
                var     repo   = new NguoiDungRepository(context);

                if (PasswordHash != "" && PasswordHash != null)
                {
                    PasswordHash = HashHelper.getHashSha256(PasswordHash);
                    repo.UpdatePartial(this,
                                       nameof(MaNguoiDung),
                                       nameof(HoTen),
                                       nameof(VaiTroId),
                                       nameof(NhanVienId),
                                       nameof(PasswordHash),
                                       nameof(Email),
                                       nameof(DienThoai)
                                       );
                }
                else
                {
                    repo.UpdatePartial(this,
                                       nameof(MaNguoiDung),
                                       nameof(HoTen),
                                       nameof(VaiTroId),
                                       nameof(NhanVienId),
                                       nameof(Email),
                                       nameof(DienThoai)
                                       );
                }
                result.data = this;
                return(returnActionResult(this, null));
            }
            catch (FormatException ex)
            {
                return(returnActionError(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                return(returnActionError(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
 public CauHinhNguoiDungService(IUnitOfWork unitOfWork) : base(unitOfWork)
 {
     _nguoiDungRepository = new NguoiDungRepository(unitOfWork);
 }
 public void SetUp()
 {
     nguoiDungRepository = new NguoiDungRepository();
 }
Beispiel #8
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            //Dummy check here, you need to do your DB checks against memebrship system http://bit.ly/SPAAuthCode
            //Begin db check user
            string email = context.UserName;

            string password = context.Password;

            NguoiDungRepository repo = new NguoiDungRepository(_context);

            NguoiDung objResult = repo.GetByEmail(email);

            if (objResult == null)
            {
                context.SetError("invalid_grant", "Không tìm thấy Email này trong hệ thống!");
                //return;
                return(Task.FromResult <object>(null));
            }

            NguoiDung objNguoiDung = objResult;

            string passwordhash = string.IsNullOrWhiteSpace(password) ? "" : HashHelper.getHashSha256(password);

            //string passwordhash = HashHelper.getHashSha256(password);

            if (!objNguoiDung.PasswordHash.Equals(passwordhash) || passwordhash.Equals(""))
            {
                context.SetError("invalid_grant", "Mật khẩu không chính xác!");
                //return;
                return(Task.FromResult <object>(null));
            }

            GetListQuyenTacVuByVaiTroIdDac getListVaiTroDal = new GetListQuyenTacVuByVaiTroIdDac(_context);

            getListVaiTroDal.VAITROID = objNguoiDung.VaiTroId;

            IEnumerable <QuyenTacVuDto> listVaiTro = getListVaiTroDal.Execute();

            listVaiTro = listVaiTro.Where(dieukien => (dieukien.DSQuyenTacVu != null && dieukien.DSQuyenTacVu.Contains("V")));

            if (listVaiTro.Count() == 0)
            {
                context.SetError("invalid_grant", "Người dùng không có quyền truy cập hệ thống!");
                //return;
                return(Task.FromResult <object>(null));
            }

            //End db check user

            var identity = new ClaimsIdentity("JWT");

            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, objNguoiDung.NguoiDungId.ToString()));
            identity.AddClaim(new Claim(ClaimTypes.Name, objNguoiDung.HoTen));
            identity.AddClaim(new Claim(ClaimTypes.Email, objNguoiDung.Email));

            identity.AddClaim(new Claim(ClaimTypes.Role, listVaiTro.FirstOrDefault().MaVaiTro));

            var nhanvienid = objNguoiDung.NhanVienId != null?objNguoiDung.NhanVienId.Value.ToString() : "";

            identity.AddClaim(new Claim("NhanVienId", nhanvienid));

            foreach (string chucnang in listVaiTro.Select(cot => cot.MaChucNang))
            {
                identity.AddClaim(new Claim("FunctionCode", chucnang));
            }

            identity.AddClaim(new Claim("jti", Guid.NewGuid().ToString()));

            var props = new AuthenticationProperties(new Dictionary <string, string>
            {
                {
                    "audience", (context.ClientId == null) ? string.Empty : context.ClientId
                }
            });

            var ticket = new AuthenticationTicket(identity, props);

            context.Validated(ticket);
            return(Task.FromResult <object>(null));
        }