Ejemplo n.º 1
0
        public void Update(DalUser entity)
        {
            var temp = _context.Users.Find(entity.UserId);

            temp = Mapper.CreateMap().Map <User>(entity);
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void Insert(DalUser entity)
        {
            var tempEntity = Mapper.CreateMap().Map <User>(entity);
            var temp       = _context.Roles.FirstOrDefault(r => r.Name.Equals(tempEntity.Roles.Name));

            tempEntity.Roles = temp;
            _context.Users.Add(tempEntity);
            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public DalPost GetPostUser(DalUser user)
        {
            DalPost UserLoginPost = null;

            using (Shop shop = new Shop())
            {
                User tmpUser = shop.Users.Where(x => x.Id == user.Id).First();
                UserLoginPost = EntityConvertToDTO.PostToDalPost(tmpUser.Post);
            };
            return(UserLoginPost);
        }
Ejemplo n.º 4
0
        public void Delete(DalUser e)
        {
            var user = new User()
            {
                Id       = e.Id,
                Login    = e.Login,
                Password = e.Password
            };

            user = context.Set <User>().Single(u => u.Id == user.Id);
            context.Set <User>().Remove(user);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The method for creating new user entity in collection
        /// </summary>
        /// <param name="dalUser"></param>
        public void Create(DalUser dalUser)
        {
            var user = dalUser.ToUser();

            foreach (var role in dalUser.Roles)
            {
                var userRole = roles.FirstOrDefault(r => r.Name == role);
                user.Roles.Add(userRole);
            }

            users.Add(user);
        }
Ejemplo n.º 6
0
        public void Create(DalUser e)
        {
            var user = new Users()
            {
                Name     = e.Name,
                Email    = e.Email,
                Password = e.Password,
                RoleId   = 2
            };

            context.Set <Users>().Add(user);
            context.SaveChanges();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Method for valid user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsValid(DalUser user)
        {
            if (ReferenceEquals(user, null))
            {
                throw new ArgumentNullException();
            }

            if (string.IsNullOrWhiteSpace(user.FirstName) || string.IsNullOrWhiteSpace(user.LastName))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
 public static User ToOrmUser(this DalUser user)
 {
     return(new User()
     {
         Id = user.Id,
         Email = user.Email,
         Login = user.Login,
         Name = user.Name,
         Password = user.Password,
         Phone = user.Phone,
         ProfilePhoto = user.ProfilePhoto,
         Roles = user.Roles
     });
 }
Ejemplo n.º 9
0
        public void Update(DalUser e)
        {
            var users = context.Set <ORM.Users>().Where(user => user.UserId.Equals(e.Id)).Select(user => new DalUser()
            {
                Name   = user.Name,
                Id     = user.UserId,
                RoleId = user.RoleId,
                Email  = user.Email
            }).FirstOrDefault();

            users.Name     = e.Name;
            users.Email    = e.Email;
            users.Password = e.Password;
            context.SaveChanges();
            context.Dispose();
        }
Ejemplo n.º 10
0
        public DalUser GetUser(string login, string password)
        {
            DalUser GetUser = null;

            using (Shop shop = new Shop())
            {
                User tmpuser = shop.Users.Where(x => x.Login.Equals(login) &&
                                                x.Password.Equals(password)).
                               FirstOrDefault();
                if (tmpuser != null)
                {
                    GetUser = EntityConvertToDTO.UserToDalUser(tmpuser);
                }
            };
            return(GetUser);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// The method for updating exsisting user in collection
        /// </summary>
        /// <param name="dalUser"></param>
        public void Update(DalUser dalUser)
        {
            var user = users.FirstOrDefault(u => u.Id == dalUser.Id);

            if (!ReferenceEquals(user, null))
            {
                user.Login            = dalUser.Login;
                user.Email            = dalUser.Email;
                user.IsEmailConfirmed = dalUser.IsEmailConfirmed;
                user.Roles.Clear();
                foreach (var item in dalUser.Roles)
                {
                    var userRole = roles.FirstOrDefault(r => r.Name == item);
                    user.Roles.Add(userRole);
                }
                context.Entry(user).State = EntityState.Modified;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Delete
        /// </summary>
        /// <param name="user"></param>
        public void Delete(DalUser user)
        {
            if (object.ReferenceEquals(user, null))
            {
                if (LoggerSwitch.Enabled)
                {
                    Logger.Error(nameof(user));
                }

                throw new ArgumentNullException();
            }

            this.users.Remove(user);
            if (LoggerSwitch.Enabled)
            {
                Logger.Info($"User {user} Deleted");
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     Add
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int Add(DalUser user)
        {
            try
            {
                var isValid = this.validator.IsValid(user);
                if (!isValid)
                {
                    throw new ArgumentException(nameof(user));
                }

                this.generator.GenerateId();
                user.Id = this.generator.Current;
            }
            catch (ArgumentNullException exception)
            {
                if (LoggerSwitch.Enabled)
                {
                    Logger.Error(exception.Message);
                }

                throw;
            }
            catch (InvalidOperationException exception)
            {
                if (LoggerSwitch.Enabled)
                {
                    Logger.Error(exception.Message);
                }

                throw;
            }

            this.users.Add(user);
            if (LoggerSwitch.Enabled)
            {
                Logger.Info($"User: {user} Added");
            }

            return(user.Id);
        }
Ejemplo n.º 14
0
        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.º 15
0
 public void Update(DalUser entity)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 public void Delete(DalUser entity)
 {
     _context.Users.Remove(Mapper.CreateMap().Map <User>(entity));
     _context.SaveChanges();
 }