コード例 #1
0
        public void Edit(CustomFieldModel viewModel, EducationSecurityPrincipal user)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            var model = CustomFieldRepository.Items.Include(c => c.Categories).SingleOrDefault(c => c.Id == viewModel.Id);

            if (model == null)
            {
                throw new EntityNotFoundException("The requested custom field could not be found");
            }
            if (CustomFieldValueRepository.Items.Any(v => v.CustomFieldId == viewModel.Id) && model.CustomFieldTypeId != viewModel.SelectedFieldTypeId)
            {
                throw new ValidationException(new ValidationResult("Cannot edit field type because data values have already been loaded", new[] { "SelectedFieldTypeId" }), null, viewModel);
            }
            viewModel.CopyTo(model);
            model.LastModifyingUser = user.Identity.User;
            model.LastModifyTime    = DateTime.Now;
            model.Categories        = CustomFieldCategoryRepository.Items.Where(c => viewModel.SelectedCategories.Contains(c.Id)).ToList();
            CustomFieldRepository.Update(model);
            RepositoryContainer.Save();
        }