Exemple #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);
            }
        }
Exemple #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);
            }
        }