示例#1
0
        public static void AddContext(this IServiceCollection services)
        {
            var contextRepository = new ContextRepository();
            var context           = contextRepository.Load();

            services.AddSingleton(c => context);
        }
        // GET: Edit A Single ClientFee
        public ActionResult Edit(int id)
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            ClientFee clientFee = new ClientFee();

            clientFee = clientFeeRepository.GetItem(id);

            //Check Exists
            if (clientFee == null)
            {
                ViewData["ActionMethod"] = "EditGet";
                return(View("RecordDoesNotExistError"));
            }

            //Change DisplayText for Transaction Fees
            FeeType feeType = new FeeType();

            feeType = clientFee.FeeType;
            if (feeType.FeeTypeDescription == "Client Fee")
            {
                feeType.FeeTypeDescription = "Transaction Fee";
            }

            ClientFeeVM clientFeeVM = new ClientFeeVM();

            clientFeeVM.ClientFee = clientFee;



            GDSRepository gdsRepository = new GDSRepository();

            clientFeeVM.GDSs = new SelectList(gdsRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName", clientFee.GDSCode);

            ContextRepository contextRepository = new ContextRepository();

            clientFeeVM.Contexts = new SelectList(contextRepository.GetAllContexts().ToList(), "ContextId", "ContextName", clientFee.ContextId);

            //Check for missing GDS
            if (clientFee.GDS == null)
            {
                GDS gds = new GDS();
                clientFee.GDS = gds;
            }

            ClientFeeOutput clientFeeOutput = new ClientFeeOutput();

            if (clientFee.ClientFeeOutputs.Count > 0)
            {
                clientFeeOutput = clientFeeOutputRepository.GetItem(clientFee.ClientFeeOutputs[0].ClientFeeOutputId);
            }
            clientFeeVM.ClientFeeOutput = clientFeeOutput;

            return(View(clientFeeVM));
        }
示例#3
0
 public CarbonFootprintViewModelFactory([ImportMany] IEnumerable <Lazy <IPositionViewModelFactory, IPositionMetadata> > factories, [Import] ContextRepository contextRepository,
                                        [Import] TagColorProvider tagColorProvider)
 {
     m_Factories         = factories;
     m_ContextRepository = contextRepository;
     m_TagColorProvider  = tagColorProvider;
 }
示例#4
0
        public void PagedListAsync_WhenSpecificationIsNull_ThrowsArgumentNullException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.ThrowsAsync <ArgumentNullException>(() => contextRepo.PagedListAsync <object>(0, 0, null));

            Assert.AreEqual("Value cannot be null. (Parameter 'specification')", exception.Message);
        }
示例#5
0
        public void Attach_WhenObjectIsNull_ThrowsArgumentNullException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.Throws <ArgumentNullException>(() => contextRepo.Attach <object>(null));

            Assert.AreEqual("Value cannot be null. (Parameter 'entity')", exception.Message);
        }
示例#6
0
        public void AddRangeAsync_WhenObjectCollectionIsEmpty_ThrowsArgumentException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.ThrowsAsync <ArgumentException>(() => contextRepo.AddRangeAsync(new List <object>()));

            Assert.AreEqual("Cannot add an empty collection. (Parameter 'entities')", exception.Message);
        }
示例#7
0
 /// <summary>
 ///
 /// </summary>
 public ContextService()
 {
     _contextRepository  = new ContextRepository();
     _signatorRepository = new SignatorRepository();
     _signatorServices   = new SignatorServices();
     _participantService = new ParticipantService();
 }
示例#8
0
        //Contexts
        private IEnumerable <SelectListItem> GetSelectedContexts(ClientDefinedReferenceItem clientDefinedReferenceItem)
        {
            ContextRepository            contextRepository = new ContextRepository();
            IEnumerable <SelectListItem> defaultContexts   = new SelectList(contextRepository.GetAllContexts().ToList(), "ContextId", "ContextName");
            List <SelectListItem>        selectedContexts  = new List <SelectListItem>();

            foreach (SelectListItem item in defaultContexts)
            {
                bool selected = false;

                if (clientDefinedReferenceItem.ClientDefinedReferenceItemContextIds != null && clientDefinedReferenceItem.ClientDefinedReferenceItemContextIds.Length > 0)
                {
                    foreach (string contextId in clientDefinedReferenceItem.ClientDefinedReferenceItemContextIds.Split(','))
                    {
                        if (item.Value == contextId)
                        {
                            selected = true;
                        }
                    }
                }

                selectedContexts.Add(
                    new SelectListItem()
                {
                    Text     = item.Text,
                    Value    = item.Value,
                    Selected = selected
                }
                    );
            }

            return(selectedContexts);
        }
示例#9
0
        public void Remove_WhenObjectCollectionIsNull_ThrowsArgumentNullException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.Throws <ArgumentNullException>(() => contextRepo.RemoveRange((ICollection <object>)null));

            Assert.AreEqual("Value cannot be null. (Parameter 'entities')", exception.Message);
        }
        // GET: Create A Single ClientFee
        public ActionResult Create()
        {
            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            ClientFeeVM clientFeeVM = new ClientFeeVM();
            ClientFee   clientFee   = new ClientFee();

            FeeType feeType = new FeeType();

            clientFee.FeeType     = feeType;
            clientFeeVM.ClientFee = clientFee;

            FeeTypeRepository feeTypeRepository = new FeeTypeRepository();

            clientFeeVM.FeeTypes = feeTypeRepository.GetAllFeeTypes().ToList();

            GDSRepository gdsRepository = new GDSRepository();

            clientFeeVM.GDSs = new SelectList(gdsRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName");

            ContextRepository contextRepository = new ContextRepository();

            clientFeeVM.Contexts = new SelectList(contextRepository.GetAllContexts().ToList(), "ContextId", "ContextName");

            return(View(clientFeeVM));
        }
            public void SetUp()
            {
                _fixture = new CustomAutoFixture();

                _expectedContextManageCount = _hasCurrentContext ? 0 : 1;

                _contextService = _fixture.Freeze <IContextService <DbContext_Fake> >();
                _dbSetService   = _fixture.Freeze <IDbSetService <DbContext_Fake, Foo> >();
                _flushService   = _fixture.Freeze <IFlushService <DbContext_Fake> >();

                _context = new DbContext_Fake();

                _contextService.HasCurrentContext().Returns(_hasCurrentContext);
                _contextService.InitContext().Returns(_context);
                _contextService.GetCurrentContext().Returns(_context);

                _dbSet = Substitute.For <DbSet <Foo>, IQueryable <Foo> >();

                _dbSetService.GetDbSet(Arg.Any <DbContext_Fake>())
                .Returns(_dbSet);

                _sut = _fixture.Create <ContextRepository <DbContext_Fake, Foo> >();

                _foo = _fixture.Create <Foo>();
            }
            public void SetUp()
            {
                _fixture = new CustomAutoFixture();

                _expectedContextManageCount = _hasCurrentContext ? 0 : 1;

                _contextService = _fixture.Freeze <IContextService <DbContext_Fake> >();
                _dbSetService   = _fixture.Freeze <IDbSetService <DbContext_Fake, Foo> >();

                _context = new DbContext_Fake();

                _contextService.HasCurrentContext().Returns(_hasCurrentContext);
                _contextService.InitContext().Returns(_context);
                _contextService.GetCurrentContext().Returns(_context);

                _expectedEntity = _fixture.Create <Foo>();

                _dbSet = CreateDbSetSubstitute(_expectedEntity);
                _dbSet.FindAsync(_expectedEntity.FooId).Returns(_expectedEntity);

                _dbSetService.GetDbSet(Arg.Any <DbContext_Fake>())
                .Returns(_dbSet);

                _sut = _fixture.Create <ContextRepository <DbContext_Fake, Foo> >();
            }
示例#13
0
        public void FindByPrimaryKeyAsync_WhenPrimaryKeyIsNull_ThrowsArgumentNullException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception   = Assert.ThrowsAsync <ArgumentNullException>(() => contextRepo.FindByPrimaryKeyAsync <object, object>(null));

            Assert.AreEqual("Value cannot be null. (Parameter 'primaryKey')", exception.Message);
        }
        public void CreateRepositoryFromGlobalContext()
        {
            var repo = new ContextRepository<Person>(new FakeContext());

            Assert.NotNull(repo);
            Assert.AreEqual(typeof(ContextRepository<Person>),repo.GetType());
        }
示例#15
0
        public void QueryAsync_WhenSpecificationIsNull_ThrowsArgumentNullException()
        {
            var contextRepo = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var resolver    = It.IsAny <Func <IQueryable <object>, Task <object> > >();
            var exception   = Assert.ThrowsAsync <ArgumentNullException>(() => contextRepo.QueryAsync(null, resolver));

            Assert.AreEqual("Value cannot be null. (Parameter 'specification')", exception.Message);
        }
示例#16
0
        public void PagedListAsync_WhenPageSizeIsLessThanOrEqualToZero_ThrowsArgumentException(int pageSize)
        {
            var mockSpecification = new Mock <LinqSpecification <object> >();
            var contextRepo       = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var exception         = Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => contextRepo.PagedListAsync(0, pageSize, mockSpecification.Object));

            Assert.AreEqual("Specified argument was out of the range of valid values. (Parameter 'pageSize')", exception.Message);
        }
        public TechPassportsViewModel()
        {
            _repo = new ContextRepository <InSQL.TechPassport>();
            _selectedTechPassport = new TechPassport();
            UpdateBtnVisibility   = StateService.StoreType == StoreType.InMemory ? "Hidden" : "Visible";

            LoadData();
        }
示例#18
0
        public ShiftsViewModel()
        {
            _repo               = new ContextRepository <InSQL.Shift>();
            _selectedShift      = new Shift();
            UpdateBtnVisibility = StateService.StoreType == StoreType.InMemory ? "Hidden" : "Visible";

            LoadData();
        }
示例#19
0
        public DriversViewModel()
        {
            _repo               = new ContextRepository <InSQL.Driver>();
            _selectedDriver     = new Driver();
            UpdateBtnVisibility = StateService.StoreType == StoreType.InMemory ? "Hidden" : "Visible";

            LoadData();
        }
示例#20
0
        public void QueryAsync_WhenResolverIsNull_ThrowsArgumentNullException()
        {
            var contextRepo           = new ContextRepository <IAuditedContext>(It.IsAny <IAuditedContext>(), It.IsAny <ILogger <IAuditedContext> >());
            var mockLinqSpecificaiton = new Mock <LinqSpecification <object> >();
            var exception             = Assert.ThrowsAsync <ArgumentNullException>(() => contextRepo.QueryAsync <object, object>(mockLinqSpecificaiton.Object, null));

            Assert.AreEqual("Value cannot be null. (Parameter 'resolver')", exception.Message);
        }
示例#21
0
        public RoutesViewModel()
        {
            _routesRepo         = new ContextRepository <InSQL.Route>();
            _shiftRepo          = new ContextRepository <InSQL.Shift>();
            _selectedRoute      = new Route();
            UpdateBtnVisibility = StateService.StoreType == StoreType.InMemory ? "Hidden" : "Visible";

            LoadData();
        }
示例#22
0
        public async Task FindByPrimaryKeyAsync_WhenContextHasNoEntities_ReturnsNull()
        {
            using (var context = new MemoryContext())
            {
                var repo = new ContextRepository <MemoryContext>(context, It.IsAny <ILogger <IAuditedContext> >());

                var entity = await repo.FindByPrimaryKeyAsync <AuditedEntity, Guid>(It.IsAny <Guid>());

                Assert.IsNull(entity);
            }
        }
示例#23
0
        // GET: /Create
        public ActionResult Create(string id, string can, string ssc)
        {
            ClientSubUnit clientSubUnit = new ClientSubUnit();

            clientSubUnit = clientSubUnitRepository.GetClientSubUnit(id);

            //Check Exists
            if (clientSubUnit == null)
            {
                ViewData["ActionMethod"] = "ListBySubUnitGet";
                return(View("RecordDoesNotExistError"));
            }

            //Check Access Rights to Domain
            if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            ClientDefinedReferenceItemVM clientDefinedReferenceItemVM = new ClientDefinedReferenceItemVM();
            ClientDefinedReferenceItem   clientDefinedReferenceItem   = new ClientDefinedReferenceItem();

            clientDefinedReferenceItemRepository.EditForDisplay(clientDefinedReferenceItem);

            if (can != null && ssc != null)
            {
                ClientSubUnitClientAccount clientSubUnitClientAccount = new ClientSubUnitClientAccount();
                clientSubUnitClientAccount = clientSubUnitClientAccountRepository.GetClientSubUnitClientAccount(can, ssc, clientSubUnit.ClientSubUnitGuid);
                if (clientSubUnitClientAccount != null)
                {
                    ViewData["ClientSubUnitClientAccountClientAccountName"] = clientSubUnitClientAccount.ClientAccount.ClientAccountName;
                }

                clientDefinedReferenceItem.ClientAccountNumber = can;
                clientDefinedReferenceItem.SourceSystemCode    = ssc;
            }

            //Products
            ProductRepository productRepository = new ProductRepository();

            clientDefinedReferenceItemVM.Products = new SelectList(productRepository.GetAllProducts().ToList(), "ProductId", "ProductName");

            //Contexts
            ContextRepository contextRepository = new ContextRepository();

            clientDefinedReferenceItemVM.Contexts = new SelectList(contextRepository.GetAllContexts().ToList(), "ContextId", "ContextName");

            clientDefinedReferenceItem.ClientSubUnitGuid            = clientSubUnit.ClientSubUnitGuid;
            clientDefinedReferenceItemVM.ClientDefinedReferenceItem = clientDefinedReferenceItem;
            clientDefinedReferenceItemVM.ClientSubUnit = clientSubUnit;

            return(View(clientDefinedReferenceItemVM));
        }
示例#24
0
        public async Task FindByPrimaryKeyAsync_VerifyDbSetFindAsyncIsCalled()
        {
            var mockContext = new Mock <IAuditedContext>();
            var mockDbSet   = new Mock <DbSet <object> >();

            mockContext.Setup(a => a.Set <object>()).Returns(mockDbSet.Object);

            var repository = new ContextRepository <IAuditedContext>(mockContext.Object, It.IsAny <ILogger <IAuditedContext> >());

            await repository.FindByPrimaryKeyAsync <object, int>(1);

            mockDbSet.Verify(a => a.FindAsync(1), Times.Once);
        }
示例#25
0
        public CarbonFootprintViewModel(CarbonFootprint cf, IEnumerable <Lazy <IPositionViewModelFactory, IPositionMetadata> > factories, ContextRepository contextRepository,
                                        string[] uniqueCarbonFootprintNames, TagColorProvider tagColorProvider, IEnumerable <ResponsibleSubjectViewModel> responsibleSubjects)
        {
            PositionFactories     = factories;
            m_ResponsibleSubjects = responsibleSubjects;
            m_ContextRepository   = contextRepository;
            Model = cf;
            m_UniqueCarbonFootprintNames = uniqueCarbonFootprintNames;
            m_TagColorProvider           = tagColorProvider;
            m_IsSelected = true;
            InitializePositions(Model);

            RemoveCommand = new RelayCommand(Remove);
        }
示例#26
0
        public SettingsViewModel(ContextRepository contextRepository, TagColorProvider tagColorProvider, ExampleDataProvider exampleDataProvider, SettingsProvider settingsProvider)
        {
            DisplayName           = "Einstellungen";
            m_ContextRepository   = contextRepository;
            m_TagColorProvider    = tagColorProvider;
            m_ExampleDataProvider = exampleDataProvider;
            m_SettingsProvider    = settingsProvider;
            m_ExampleDataProvider.SeedCompleted += (s, e) => Save();

            ServerUrl  = m_SettingsProvider.Url;
            ServerPort = m_SettingsProvider.Port;
            UserName   = m_SettingsProvider.UserName;
            Password   = m_SettingsProvider.Password;
        }
        public WorkspaceViewModel(CarbonFootprintViewModelFactory carbonFootprintViewModelFactory, ContextRepository repository, TagColorProvider tagProvider)
        {
            DisplayName = "Carbon Footprints";
            m_CarbonFootprintViewModelFactory = carbonFootprintViewModelFactory;
            m_Repository  = repository;
            m_TagProvider = tagProvider;

            m_Repository.SaveCompleted  += SaveCompleted;
            m_Repository.ContextChanged += (s, e) => LoadData();

            RefreshStateVisibility = Visibility.Collapsed;

            EditCommand   = new RelayCommand(x => Edit((CarbonFootprintViewModel)x));
            RemoveCommand = new RelayCommand(Remove);
        }
        public ActionResult Create(int id)
        {
            //Get QueueMinderGroup
            QueueMinderGroup queueMinderGroup = new QueueMinderGroup();

            queueMinderGroup = queueMinderGroupRepository.GetGroup(id);

            //Check Exists
            if (queueMinderGroup == null)
            {
                ViewData["ActionMethod"] = "CreateGet";
                return(View("RecordDoesNotExistError"));
            }
            RolesRepository rolesRepository = new RolesRepository();

            if (!rolesRepository.HasWriteAccessToQueueMinderGroup(id))
            {
                ViewData["Message"] = "You do not have access to this item";
                return(View("Error"));
            }

            QueueMinderItemVM queueMinderItemVM = new QueueMinderItemVM();

            QueueMinderItem queueMinderItem = new QueueMinderItem();

            queueMinderItem.QueueMinderGroup  = queueMinderGroup;
            queueMinderItemVM.QueueMinderItem = queueMinderItem;

            GDSRepository gDSRepository = new GDSRepository();
            SelectList    gDSs          = new SelectList(gDSRepository.GetAllGDSs().ToList(), "GDSCode", "GDSName");

            queueMinderItemVM.GDSs = gDSs;

            ContextRepository contextRepository = new ContextRepository();
            SelectList        contexts          = new SelectList(contextRepository.GetAllContexts().ToList(), "ContextId", "ContextName");

            queueMinderItemVM.Contexts = contexts;

            //DONT SHOW 17,18,19 UNLESS ROLE ALLOWS
            QueueMinderTypeRepository queueMinderTypeRepository = new QueueMinderTypeRepository();
            SelectList queueMinderTypes = new SelectList(queueMinderTypeRepository.GetAllQueueMinderTypes().ToList(), "QueueMinderTypeId", "QueueMinderTypeDescription");

            queueMinderItemVM.QueueMinderTypes = queueMinderTypes;

            return(View(queueMinderItemVM));
        }
示例#29
0
        public void Remove_WhenRemovingObject_VerifyDbSetRemoveIsCalled()
        {
            var @object     = new object();
            var mockContext = new Mock <IAuditedContext>();
            var mockDbSet   = new Mock <DbSet <object> >();

            mockContext.Setup(a => a.Set <object>()).Returns(mockDbSet.Object);

            var repository = new ContextRepository <IAuditedContext>(mockContext.Object, It.IsAny <ILogger <IAuditedContext> >());

            repository.Remove(@object);

            Assert.Multiple(() =>
            {
                mockDbSet.Verify(a => a.Remove(@object), Times.Once);
                mockContext.Verify(c => c.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never, "Context should never saved.");
            });
        }
示例#30
0
        public async Task AddRangeAsync_WhenAddingCollection_VerifyDbSetAddRangeAsyncIsCalled()
        {
            var objects = new List <object> {
                new object()
            };
            var mockContext = new Mock <IAuditedContext>();
            var mockDbSet   = new Mock <DbSet <object> >();

            mockContext.Setup(a => a.Set <object>()).Returns(mockDbSet.Object);

            var repository = new ContextRepository <IAuditedContext>(mockContext.Object, It.IsAny <ILogger <IAuditedContext> >());

            await repository.AddRangeAsync(objects);

            Assert.Multiple(() =>
            {
                mockDbSet.Verify(a => a.AddRangeAsync(objects, It.IsAny <CancellationToken>()), Times.Once);
                mockContext.Verify(c => c.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never, "Context should never saved.");
            });
        }
示例#31
0
        //Полиморфный объект общий для всех журналов выполненных работ.
        //По тиму модели базы вызывается необходимая стратегия

        /// <summary>
        /// Удалить запись журнала
        /// </summary>
        private async System.Threading.Tasks.Task <JsonResult> DeleteAsync <ModelDb>(int id) where ModelDb : class
        {
            #region Проверка существования записи в соответствующем журнале
            // CollectionStrategyWorksJournal Коллекция стратегий в одтельном файле - CollectionStrategyWorksJournal
            var strategy = new CollectionStrategyWorksJournal <ModelDb>(UnitOfWork)
                           .GetStategyCore();

            if ((await strategy.SelectByIdAsync(id)) == null)
            {
                LogProxy.Log(new DataLog(level: LogLevel.Warn, message: "Ошибка при удалении. Не удалось найти запись", id: id.ToString(), context: ContexLog.ExecutedWorkJournal));
                return(Json(ConstMessage.DeleteUnexpectedError, JsonRequestBehavior.AllowGet));
            }

            #endregion

            try
            {
                var repExecutedWorksJournal = new ContextRepository <ExecutedWorkJournal>(UnitOfWork.RepositoryExecutedWorkJournal);

                var journal = await UnitOfWork.RepositoryExecutedWorksJournal.SelectByIdAsync(id);

                var machine = await UnitOfWork.RepositoryRefMachine.SelectByIdAsync(journal.FkMachine);

                var workArea = await UnitOfWork.RepositoryRefWorkArea.SelectByIdAsync(machine.WorkArea);

                //Пометим как удаленную
                journal.IsDeleted = OracleBoolCharExtentions.ToString(true);
                repExecutedWorksJournal.Update(journal);

                LogProxy.Log(new DataLog(level: LogLevel.Info, message: "Удалено. Участок - " + workArea.Name + ", станок " + machine.Name, id: id.ToString(), jsonData: journal, context: ContexLog.ExecutedWorkJournal));

                return(Json(ConstMessage.DeleteSuccess, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                LogProxy.Log(new DataLog(level: LogLevel.Error, message: "Ошибка при удалении записи журнала выполненных работ", id: id.ToString(), context: ContexLog.ExecutedWorkJournal, e: e));

                return(Json(ConstMessage.DeleteUnexpectedError, JsonRequestBehavior.AllowGet));
            }
        }