public bool LoginUserIsValid(LoginViewModel user) { if(user !=null) { var query = (from u in db.User where u.Username == user.Username select u).FirstOrDefault(); if (query != null) { if (ValidatePassword(user.Password, CreateHash(query.Password, query.Salt))) { userValue = query; return true; } else { return false; } } } return false; }
public void CreateUser(RegisterViewModel user) { OperationGroup group = db.OperationGroup.Where(m => m.Name == "Users").FirstOrDefault(); if (user!=null) { User newUser = new User(); newUser.Id = user.Id; newUser.Username = user.Username; newUser.Salt = CreateSalt(); newUser.Password = user.Password; newUser.IsActive = true; newUser.data = DateTime.UtcNow.AddYears(1); newUser.Operations = new List<Operation>(); newUser.OperationGroups = new List<OperationGroup>(); newUser.OperationGroups.Add(group); foreach (Operation oper in group.Operations) { if (!newUser.Operations.Contains(oper)) { newUser.Operations.Add(oper); } } db.User.Add(newUser); db.SaveChanges(); } }
public void EditUser(User user) { db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); }
public void ChangeActivation(User user) { var obj = Find(user.Id); if (obj == null) return; obj.data = user.data; if(obj.data>DateTime.UtcNow) { obj.IsActive = true; } else { obj.IsActive = false; } db.SaveChanges(); }