Esempio n. 1
0
        public static bool Register(string userName, string firstName, string lastName, string passWord, string mobileNo, string degree, string description)
        {
            PhysicUser UserEntity = new PhysicUser()
            {
                FirstName = firstName,
                IsActive  = true,
                Mobile    = mobileNo,
                LastName  = lastName,
                Password  = EncryptPassword(userName, passWord),
                Username  = userName,
                Degree    = degree,

                Description = description,
            };

            var Validation = new PhysicUserValidation.PhysicUserEntityValidation().Validate(UserEntity);

            if (Validation.IsValid)
            {
                using (var db = new Model.PhysicManagementEntities())
                {
                    if (!IsUserValidByUserName(userName))
                    {
                        throw new ValidationException("این نام کاربری تکراری است");
                    }
                    else
                    {
                        db.PhysicUser.Add(UserEntity);
                        return(db.SaveChanges() == 1);
                    }
                }
            }
            throw new ValidationException(Validation.Errors);
        }
Esempio n. 2
0
        public bool AddPhysicUser(Model.PhysicUser entity)
        {
            var vallidtion = new PhysicUserValidation.PhysicUserEntityValidation().Validate(entity);

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

            using (var db = new Model.PhysicManagementEntities())
            {
                entity.Password = EncryptPassword(entity.Username, entity.Password);
                db.PhysicUser.Add(entity);
                return(db.SaveChanges() == 1);
            }
        }
Esempio n. 3
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 PhysicUserValidation.PhysicUserEntityValidation().Validate(currentUser);

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