Ejemplo n.º 1
0
        public static bool Register(string userName, string firstName, string lastName, string passWord, string mobileNo)
        {
            User UserEntity = new User()
            {
                FirstName    = firstName,
                Mobile       = mobileNo,
                LastName     = lastName,
                Password     = EncryptPassword(userName, passWord),
                Username     = userName,
                IsSupervisor = true,
                IsActive     = true
            };

            var validation = new UserValidation.UserEntityValidate().Validate(UserEntity);

            if (validation.IsValid)
            {
                using (var db = new Model.PhysicManagementEntities())
                {
                    if (IsUserValidByUserName(userName))
                    {
                        throw new ValidationException("این نام کاربری تکراری است");
                    }
                    else
                    {
                        db.User.Add(UserEntity);
                        return(db.SaveChanges() == 1);
                    }
                }
            }
            throw new ValidationException(validation.Errors);
        }
Ejemplo n.º 2
0
        public bool AddUser(Model.User entity)
        {
            var validation = new UserValidation.UserEntityValidate().Validate(entity);

            if (!validation.IsValid)
            {
                throw new ValidationException(validation.Errors);
            }

            using (var db = new Model.PhysicManagementEntities())
            {
                db.User.Add(entity);
                return(db.SaveChanges() == 1);
            }
        }
Ejemplo n.º 3
0
        public bool UpdateUser(Model.User entity)
        {
            var validation = new UserValidation.UserEntityValidate().Validate(entity);

            if (!validation.IsValid)
            {
                throw new ValidationException(validation.Errors);
            }

            using (var db = new Model.PhysicManagementEntities())
            {
                var Entity = db.User.Find(entity.Id);
                Entity.FirstName    = entity.FirstName;
                Entity.LastName     = entity.LastName;
                Entity.Username     = entity.Username;
                Entity.Mobile       = entity.Mobile;
                Entity.Password     = entity.Password;
                Entity.IsSupervisor = entity.IsSupervisor;
                Entity.RegisterDate = entity.RegisterDate;
                Entity.Gender       = entity.Gender;

                return(db.SaveChanges() == 1);
            }
        }
Ejemplo n.º 4
0
        public static bool UpdateProfile(int id, string userName, string firstName, string lastName, string mobileNo)
        {
            var currentUser = GetUserByUserId(id);

            if (currentUser == null)
            {
                throw MegaException.ThrowException("چنین کاربری در سامانه پیدا نشد.");
            }

            currentUser.FirstName = firstName;
            currentUser.LastName  = lastName;
            currentUser.Mobile    = mobileNo;
            var validation = new UserValidation.UserEntityValidate().Validate(currentUser);

            if (validation.IsValid)
            {
                using (var db = new Model.PhysicManagementEntities())
                {
                    db.User.Add(currentUser);
                    return(db.SaveChanges() == 1);
                }
            }
            throw new ValidationException(validation.Errors);
        }