Exemplo n.º 1
0
        public bool Update(Teacher model)
        {
            try
            {
                //Get item user with Id from database
                var item = context.Teachers.Where(i => i.ID == model.ID).FirstOrDefault();

                //Set value item with value from model
                item.MaGV         = model.MaGV;
                item.SubjectID    = model.SubjectID;
                item.FirstName    = model.FirstName;
                item.LastName     = model.LastName;
                item.Sex          = model.Sex;
                item.Birthday     = model.Birthday;
                item.Address      = model.Address;
                item.Email        = model.Email;
                item.Phone        = model.Phone;
                item.PasswordSalt = PasswordHash.GeneratePasswordSalt();
                item.Password     = PasswordHash.EncryptionPasswordWithSalt(model.Password, PasswordHash.GeneratePasswordSalt());
                item.ModifiedBy   = model.ModifiedBy;
                item.ModifiedTime = DateTime.Now;
                item.Note         = model.Note;

                //Save change to database
                context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool Create(Teacher model)
        {
            try
            {
                //Initialization empty item
                var item = new Teacher();

                //Set value for item with value from model
                item.MaGV         = model.MaGV;
                item.SubjectID    = model.SubjectID;
                item.FirstName    = model.FirstName;
                item.LastName     = model.LastName;
                item.Sex          = model.Sex;
                item.Birthday     = model.Birthday;
                item.Address      = model.Address;
                item.Email        = model.Email;
                item.Phone        = model.Phone;
                item.PasswordSalt = PasswordHash.GeneratePasswordSalt();
                item.Password     = PasswordHash.EncryptionPasswordWithSalt(model.Password, PasswordHash.GeneratePasswordSalt());
                item.CreateBy     = model.ModifiedBy;
                item.CreateTime   = DateTime.Now;
                item.Note         = model.Note;

                //Add item to entity
                context.Teachers.Add(item);
                //Save to database
                context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public Teacher LoginByCredential(string magv, string password)
        {
            if (string.IsNullOrEmpty(magv) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            var gv = teacherDAL.GetByMagv(magv);

            if (gv == null)
            {
                return(null);
            }

            var passwordSalt    = gv.PasswordSalt;
            var passwordEncrypt = PasswordHash.EncryptionPasswordWithSalt(password, passwordSalt);

            if (passwordEncrypt == gv.Password)
            {
                return(gv);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public User LoginByCredential(string username, string password)
        {
            UserDAL userDAL = new UserDAL();

            if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                return(null);
            }

            var user = userDAL.GetByUsername(username);

            if (user == null)
            {
                return(null);
            }

            var passwordSalt    = user.PasswordSalt;
            var passwordEncrypt = PasswordHash.EncryptionPasswordWithSalt(password, passwordSalt);

            if (passwordEncrypt == user.PasswordEncrypted)
            {
                return(user);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public Student LoginByCredential(string masv, string password)
        {
            if (string.IsNullOrEmpty(masv) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            var sv = studentDAL.GetByMasv(masv);

            if (sv == null)
            {
                return(null);
            }

            var passwordSalt    = sv.PasswordSalt;
            var passwordEncrypt = PasswordHash.EncryptionPasswordWithSalt(password, passwordSalt);

            if (passwordEncrypt == sv.Password)
            {
                return(sv);
            }
            else
            {
                return(null);
            }
        }