Ejemplo n.º 1
0
 public void Create(DalUser entity)
 {
     var user = entity.ToUser();
     user.Roles = user.Roles.Select(t => _dbContext.Set<Role>().Find(t.RoleId)).ToList();
     AttachRoles(user.Roles);
     _dbContext.Set<User>().Add(user);
 }
Ejemplo n.º 2
0
        public void Update(DalUser entity)
        {
            var updatedUser = entity.ToUser();
            var existedUser = _dbContext.Entry<User>(_dbContext.Set<User>().Find(updatedUser.UserId));
            if (existedUser == null)
            {
                return;
            }
            existedUser.State = EntityState.Modified;
            existedUser.Collection(u => u.Roles).Load();

            existedUser.Entity.Roles.Clear();

            foreach (Role role in updatedUser.Roles)
            {
                var loaded = _dbContext.Set<Role>().Find(role.RoleId);
                existedUser.Entity.Roles.Add(loaded);
            }

            existedUser.Entity.BlockReason = entity.BlockReason;
            existedUser.Entity.BlockTime = entity.BlockTime;
            existedUser.Entity.IsBlocked = entity.IsBlocked;
            existedUser.Entity.Photo = entity.Photo;
            existedUser.Entity.Login = entity.Login;
            existedUser.Entity.Email = entity.Email;
            existedUser.Entity.Password = entity.Password;
        }
 public IEnumerable<DalProject> GetAllProjectsByUser(DalUser user)
  {
      var ormuser = context.Set<User>().Single(u => u.UserId == user.Id);
      var Projects = ormuser.Projects;
      return Projects.Select(p => new DalProject() {
          Id = p.ProjectId,
          Name = p.Name
      });
  }
 public void AddUserToProject(DalUser user,int projectId)
 {
    
     var user2 = context.Set<User>().Single(u => u.UserId == user.Id);
     var project = context.Set<Project>().Single(p => p.ProjectId == projectId);
     project.Users.Add(user2);
     user2.Projects.Add(project);
     context.SaveChanges();
 }
Ejemplo n.º 5
0
 public void Create(DalUser e)
 {
     var user = new User
     {
         Login = e.Login,
         Password = e.Password,
         RoleId = e.RoleId
     };
     context.Set<User>().Add(user);
 }
 public void Update(DalUser e)
 {
     var user = _context.Set<UserLogin>().Single(u => u.Id == e.Id);
     user.UserDisplayName = e.UserDisplayName;
     user.UserEmail = e.UserEmail;
     if (!string.IsNullOrEmpty(e.UserPassword))
     user.UserPassword = e.UserPassword;
     user.UserBanned = e.UserBanned;
     _context.Entry(user).State=EntityState.Modified;
 }
Ejemplo n.º 7
0
 public static User ToOrmUser(this DalUser e)
 {
     return(new User()
     {
         Id = e.Id,
         Name = e.Name,
         Password = e.Password,
         Publications = e.Publications?.Select(x => ToOrmContent(x)).ToList(),
         Roles = e.Roles?.Select(x => ToOrmRole(x)).ToList()
     });
 }
 public void Create(DalUser e)
 {
     var user = new User()
     {
         Login = e.Login,
         Role_Id = e.Role_Id,
         Password = e.Password,
         RegistryDate = DateTime.Now,
         E_mail = e.E_mail
     };
     context.Set<User>().Add(user);
 }
Ejemplo n.º 9
0
        public int UpVote(DalContent content, DalUser user)
        {
            var originalUser = context.Set<User>().First(u => u.Id == user.Id);
            var originalContent = context.Set<Content>().First(u => u.Id == content.Id);

            if (!originalUser.VotedPublications.Contains(originalContent))
            {
                originalContent.Rating++;
                originalUser.VotedPublications.Add(originalContent);
            }
            return (int)originalContent.Rating;
        }
Ejemplo n.º 10
0
 public void Create(DalUser e)
 {
     var user = new User()
     {
         Email = e.Email,
         CreationDate = e.CreationDate,
         Password = e.Password,
         RoleId = e.RoleId
     };
     context.Set<User>().Add(user);
     context.SaveChanges();
 }
 public void Create(DalUser entity)
 {
     var user = new Users()
     {
         Name = entity.Name,
         Login = entity.Login,
         Password = entity.Password,
         Role = entity.RoleId
     };
     context.Set<Users>().Add(user);
     context.SaveChanges();
 }
Ejemplo n.º 12
0
 public void Create(DalUser entity)
 {
     User user = new User()
     {
         Name = entity.Name,
         Email = entity.Email,
         Password = entity.Password,
         CreationDate = entity.CreationDate,
         RoleId = entity.RoleId
     };
     _context.Set<User>().Add(user);
 }
Ejemplo n.º 13
0
 public void Delete(DalUser entity)
 {
     User user = new User()
     {
         Id = entity.Id,
         Name = entity.Name,
         Email = entity.Email,
         Password = entity.Password,
         CreationDate = entity.CreationDate,
         RoleId = entity.RoleId
     };
     user = _context.Set<User>().Single(u => u.Id == user.Id);
     _context.Set<User>().Remove(user);
 }
Ejemplo n.º 14
0
 public void Delete(DalUser e)
 {
     var user = context.Set<User>().Single(u => u.UserId == e.Id);
     var profile = context.Set<Profile>().Single(p => p.UserId == user.UserId);
     foreach(var project in user.Projects)
     {
         project.Users.Remove(user);
     }
     var tasks = context.Set<ORM.Task>().Where(t => t.UserId == user.UserId);
     context.Set<ORM.Task>().RemoveRange(tasks);
     context.Set<Profile>().Remove(profile);
     context.Set<User>().Remove(user);
     context.SaveChanges();
 }
 public void Delete(DalUser entity)
 {
     var user = new Users()
     {
         Id = entity.Id,
         Name = entity.Name,
         Login = entity.Login,
         Password = entity.Password,
         Role = entity.RoleId
     };
     user = context.Set<Users>().Single(u => u.Id == user.Id);
     context.Set<Users>().Remove(user);
     context.SaveChanges();
 }
Ejemplo n.º 16
0
 public DalUser Create(DalUser e)
 {
     if (UserExists(e.Name))
         return null;
     var user = e.ToOrmUser();
     
     var temproles = user.Roles;
     user.Roles.Clear();
     foreach (var role in temproles)
     {
         user.Roles.Add(context.Set<Role>().First(x => x.Id == role.Id));
     }
     user = context.Set<User>().Add(user);
     return user.ToDalUser();
 }
Ejemplo n.º 17
0
 public void Create(DalUser e)
 {
     var user = new User()
     {
         Name = e.Name,
         Password = e.Password,
         Email = e.Email,
         Roles = new List<Role>()
     };
     foreach (var dalRole in e.Roles)
     {
         user.Roles.Add(context.Set<Role>().FirstOrDefault(m => m.Name == dalRole.Name));
     }
     context.Set<User>().Add(user);
     context.SaveChanges();
 }
Ejemplo n.º 18
0
        public void Update(DalUser entity)
        {
            var original = context.Set<User>().FirstOrDefault(u => u.Id == entity.Id);
            if (original != null)
            {
                var updatedUser = entity.ToOrmUser();

                if (updatedUser.Name != null)
                    original.Name = updatedUser.Name;
                if (updatedUser.Password != null)
                    original.Password = updatedUser.Password;
                original.Roles.Clear();
                foreach (var role in updatedUser.Roles)
                {
                    original.Roles.Add(context.Set<Role>().First(x => x.Id == role.Id));
                }
            }
        }
Ejemplo n.º 19
0
        public void Delete(DalUser e)
        {
            var user = e.ToOrmUser();
            user = context.Set<User>().FirstOrDefault(u => u.Id == user.Id);
            if (user != null)
            {
                while (user.Publications != null && user.Publications.Any())
                {
                    context.Set<Content>().Remove(user.Publications.First());
                }
                while (user.Comments != null && user.Comments.Any())
                {
                    context.Set<Comment>().Remove(user.Comments.First());
                }
                context.Set<User>().Remove(user);
            }

        }
 public void Create(DalUser e)
 {
     var prof = new UserProfile()
     {
         FirstName = e.Profile.FirstName,
         LastName = e.Profile.LastName,
         Email = e.Profile.Email,
         BirthDate = e.Profile.BirthDate
     };
     var user = new User()
     {
         Login = e.Login,
         Password = e.Password,
         Roles = new HashSet<Role> { context.Set<Role>().FirstOrDefault(r => r.Id == e.RoleId) },
         Profile = prof
     };
     context.Set<User>().Add(user);
     //context.Set
 }
Ejemplo n.º 21
0
 public void Update(DalUser e)
 {
     var user = context.Set<User>().Single(u => u.UserId == e.Id);
     user.Email = e.Email;
     user.RoleId = e.RoleId;
     context.Entry(user).State= System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
     
 }
 public void Update(DalUser e)
 {
     var user = context.Set<User>().Where(m => m.Id == e.Id).FirstOrDefault();
     user.Login = e.Login;
     user.Password = e.Password;
     user.RegistryDate = e.RegistryDate;
     user.Role_Id = e.Role_Id;
     user.E_mail = e.E_mail;
 }
 public void Delete(DalUser e)
 {
     var user = e.ToOrmUser();
     user = _context.Set<UserLogin>().Single(u => u.Id == user.Id);
     _context.Set<UserLogin>().Remove(user);
 }
 public void Delete(DalUser e)
 {
     context.Set<User>().Remove(context.Set<User>().Where(m => m.Id == e.Id).FirstOrDefault());
 }
Ejemplo n.º 25
0
        public void Delete(DalUser entity)
        {
            var user = entity.ToUser();
            user.Roles = _roleRepository.GetRolesByUserId(user.UserId).ToRoleCollection();
            user = _dbContext.Set<User>().Single(u => u.UserId == user.UserId);

            _dbContext.Set<User>().Remove(user);
        }
 public void Update(DalUser entity)
 {
     var user = new Users()
     {
         Id = entity.Id,
         Name = entity.Name,
         Login = entity.Login,
         Password = entity.Password,
         Role = entity.RoleId
     };
     context.Set<Users>().Attach(user);
     var entry = context.Entry(user);
     entry.Property(x => x.Login).IsModified = true;
     entry.Property(x => x.Password).IsModified = true;
     entry.Property(x => x.Name).IsModified = true;
     entry.Property(x => x.Role).IsModified = true;
     context.SaveChanges();
 }
 public void CloseAllLotsCreatedByUser(DalUser user)
 {
     var ormLots =
         _context.Set<Lot>()
             .Where(x => x.CreatedByUserId == user.Id)
             .Where(x => x.LotClosed == false)
             .Where(x => x.LotEnded == false);
     foreach (var lot in ormLots)
     {
         lot.LotClosed = true;
         _context.Entry(lot).State=EntityState.Modified;
     }
 }
Ejemplo n.º 28
0
        public void Delete(DalUser entity)
        {
            var user = context.Set<User>().Where(u => u.Id == entity.Id).FirstOrDefault();
            var userRoles = context.Set<RoleUser>().Where(role => role.UserId == user.Id);
            if (userRoles != null)
            {
                foreach (var userRole in userRoles)
                {
                    context.Set<RoleUser>().Remove(userRole);
                }
            }
            if (user != null)
            {
                context.Set<User>().Remove(user);
            }

        }
Ejemplo n.º 29
0
 public void Delete(DalUser e)
 {
     var user = context.Set<User>().SingleOrDefault(u => u.Id == e.Id);
     if (user != null)
         context.Set<User>().Remove(user);
 }
Ejemplo n.º 30
0
 public void Create(DalUser entity)
 {
     var user = new User()
     {
         Id = entity.Id,
         Name = entity.Name,
         Surname = entity.Surname,
         Login = entity.Login,
         Password = entity.Password,
         Email = entity.Email,
         IsBlocked = entity.IsBlocked,
         LastUpdateDate = entity.DateAdded
     };
    
     context.Set<User>().Add(user);
   
 }
Ejemplo n.º 31
0
        public void Update(DalUser entity)
        {
            var user = context.Set<User>().Where(u => u.Id == entity.Id).FirstOrDefault();
            if (user != null)
            {
                user.Name = entity.Name;
                user.Surname = entity.Surname;
                user.Login = entity.Login;
                user.Password = entity.Password;
                user.Email = entity.Email;
                user.DateAdded = entity.DateAdded;
                user.IsBlocked = entity.IsBlocked;
                user.LastUpdateDate = DateTime.Now;            

            }
        }