Пример #1
0
        /// <summary>
        /// 保存Medium对象
        /// </summary>
        void IMediumMgr.Save(Medium medium)
        {
            List <ValidationResult> results = new List <ValidationResult>();
            bool isValid = Validator.TryValidateObject(medium,
                                                       new ValidationContext(medium),
                                                       results);

            if (!isValid)
            {
                throw new ArgumentException("介质数据不合法!");
            }

            if (medium.IsTransient())
            {
                medium.GenerateNewIdentity();
                _mediumRepository.Add(medium);
            }
            else
            {
                _mediumRepository.Modify(medium);
            }

            _mediumRepository.UnitOfWork.Commit();
        }