コード例 #1
0
        public dynamic Add(ServiceTypeDto item)
        {
            ServiceType serviceType = MapperHelper <ServiceType, ServiceTypeDto> .ConvertToModel(item);

            var output = _repository.Add(serviceType);

            output["Output"] = MapperHelper <ServiceType, ServiceTypeDto> .ConvertToDto(output["Output"]);

            return(output);
        }
コード例 #2
0
        public void AddNewServiceType()
        {
            var serviceType = new ServiceType();
            var context     = new Mock <TicketDbContext>();
            var dbSetMock   = new Mock <DbSet <ServiceType> >();

            context.Setup(x => x.Set <ServiceType>()).Returns(dbSetMock.Object);
            dbSetMock.Setup(x => x.Add(It.IsAny <ServiceType>())).Returns(serviceType);

            var repository = new ServiceTypeRepository(context.Object);

            repository.Add(serviceType);

            context.Verify(x => x.Set <ServiceType>());
            dbSetMock.Verify(x => x.Add(It.Is <ServiceType>(y => y == serviceType)));
        }
コード例 #3
0
        public void Create(ServiceTypeModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            ServiceType item = new ServiceType {
                IsActive = true
            };

            viewModel.CopyTo(item);
            if (ServiceTypeRepository.Items.Any(s => s.Name == item.Name && !s.IsActive))
            {
                item          = ServiceTypeRepository.Items.Include("ServiceOfferings.Program.Schools").Single(s => s.Name == item.Name);
                item.IsActive = true;
            }
            else
            {
                ServiceTypeRepository.Add(item);
            }
            UpdateTypeCategories(viewModel.SelectedCategories, item);
            UpdateServiceTypePrograms(viewModel.SelectedPrograms, item);
            RepositoryContainer.Save();
        }