public bool AddDoctor(Model.Doctor entity)
        {
            var validation = new DoctorValidation.DoctorEntityValidate().Validate(entity);

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

            using (var db = new Model.PhysicManagementEntities())
            {
                entity.IsActive = true;
                entity.Password = EncryptPassword(entity.Username, entity.Password);
                db.Doctor.Add(entity);
                return(db.SaveChanges() == 1);
            }
        }
        public bool UpdateDoctor(Model.Doctor entity)
        {
            var validation = new DoctorValidation.DoctorEntityValidate().Validate(entity);

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

            using (var db = new Model.PhysicManagementEntities())
            {
                var Entity = db.Doctor.Find(entity.Id);
                Entity.FirstName   = entity.FirstName;
                Entity.LastName    = entity.LastName;
                Entity.Gender      = entity.Gender;
                Entity.Mobile      = entity.Mobile;
                Entity.Code        = entity.Code;
                Entity.Degree      = entity.Degree;
                Entity.Description = entity.Description;
                Entity.Password    = EncryptPassword(entity.Username, entity.Password);

                return(db.SaveChanges() == 1);
            }
        }
        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 DoctorValidation.DoctorEntityValidate().Validate(currentUser);

            if (validation.IsValid)
            {
                using (var db = new Model.PhysicManagementEntities())
                {
                    db.Doctor.Add(currentUser);
                    return(db.SaveChanges() == 1);
                }
            }
            throw new ValidationException(validation.Errors);
        }
        public static bool Register(string userName, string firstName, string lastName, string passWord, string mobileNo, string code, string degree, string description, string expertiseMajor, string gender, ICollection <MedicalRecord> medicalRecords)
        {
            Doctor UserEntity = new Doctor()
            {
                FirstName      = firstName,
                IsActive       = true,
                Mobile         = mobileNo,
                LastName       = lastName,
                Password       = EncryptPassword(userName, passWord),
                Username       = userName,
                Code           = code,
                Gender         = gender,
                Degree         = degree,
                Description    = description,
                ExpertiseMajor = expertiseMajor
            };

            var validation = new DoctorValidation.DoctorEntityValidate().Validate(UserEntity);

            if (validation.IsValid)
            {
                using (var db = new Model.PhysicManagementEntities())
                {
                    if (IsUserValidByUserName(userName))
                    {
                        throw new ValidationException("این نام کاربری تکراری است");
                    }
                    else
                    {
                        db.Doctor.Add(UserEntity);
                        return(db.SaveChanges() == 1);
                    }
                }
            }
            throw new ValidationException(validation.Errors);
        }