Ejemplo n.º 1
0
 public bool UserNameIsNoExists(RegisterViewModel user)
 {
     if(user!=null)
     {
         var query = (from u in db.User
                      where u.Username == user.Username
                      select u).FirstOrDefault();
         if(query==null)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
        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();

            }
        }