コード例 #1
0
        /// <summary>
        /// Add new product recipe relation.
        /// </summary>
        /// <param name="model">Product recipe relation to be added</param>
        /// <returns>Added product recipe relation with correct key(ProductId, RecipeId) value</returns>
        public async Task <RecipeProductChanges> AddDataModelAsync(RecipeProductChanges model)
        {
            var entity = db.Add(model);
            await db.SaveChangesAsync();

            return(entity.Entity);
        }
コード例 #2
0
        /// <summary>
        /// Add new tech process.
        /// </summary>
        /// <param name="model">Tech process to be added</param>
        /// <returns>Added tech process with correct key(FacilityId, RecipeId) value</returns>
        public async Task <TechProcess> AddDataModelAsync(TechProcess model)
        {
            var entity = db.Add(model);
            await db.SaveChangesAsync();

            return(entity.Entity);
        }
コード例 #3
0
        /// <summary>
        /// Add new facility.
        /// </summary>
        /// <param name="model">Facility to be added</param>
        /// <returns>Added facility with correct key(Id) value</returns>
        public async Task <Facility> AddDataModelAsync(Facility model)
        {
            model.Id = default;
            var entity = db.Add(model);
            await db.SaveChangesAsync();

            return(entity.Entity);
        }
コード例 #4
0
ファイル: StoragesLogic.cs プロジェクト: No0zZy/Cursed
        /// <summary>
        /// Add new storage.
        /// </summary>
        /// <param name="model">Storage to be added</param>
        /// <returns>Added storage with correct key(Id) value</returns>
        public async Task <Storage> AddDataModelAsync(Storage model)
        {
            model.Id = default;
            var entity = db.Add(model);
            await db.SaveChangesAsync();

            return(entity.Entity);
        }
コード例 #5
0
        /// <summary>
        /// Add new product to catalog.
        /// </summary>
        /// <param name="model">Product to be added to catalog</param>
        /// <returns>Added product from catalog with correct key(Id) value</returns>
        public async Task <ProductCatalog> AddDataModelAsync(ProductCatalog model)
        {
            model.Id = default;
            var entity = db.Add(model);
            await db.SaveChangesAsync();

            return(entity.Entity);
        }
コード例 #6
0
ファイル: OperationsLogic.cs プロジェクト: No0zZy/Cursed
        /// <summary>
        /// Add new operation.
        /// </summary>
        /// <param name="model">Operation to be added</param>
        /// <returns>Added operation with correct key(Id) value</returns>
        public async Task <Operation> AddDataModelAsync(Operation model)
        {
            model.Id = default;
            var entity = db.Add(model);
            await db.SaveChangesAsync();

            return(entity.Entity);
        }
コード例 #7
0
ファイル: TransactionsLogic.cs プロジェクト: No0zZy/Cursed
        /// <summary>
        /// Applys/undos all operations recorded in specific transaction. Is applying done or undoing, is
        /// determined by transaction status (closed/open)
        /// </summary>
        /// <param name="id">Id of transaction to be found</param>
        private async Task ChangeTransactionOpenStateAsync(int id)
        {
            // gather current transaction information
            var transaction = db.TransactionBatch.Single(i => i.Id == id);

            // apply/undo each operation in current tansaction
            foreach (var operation in await db.Operation.Where(i => i.TransactionId == id).ToListAsync())
            {
                // product, which quantity will be increased
                Product productInc;
                // product, which quantity will be decrased
                Product productDec;
                // id of storage at which product quantity will be increased
                int storageIdForInc;

                // initialized delcared variables, depending on transaction status
                if (transaction.IsOpen)
                {
                    // if we applying operations, products come from From to To storage
                    productDec = await db.Product.FirstOrDefaultAsync(i => i.Uid == operation.ProductId && i.StorageId == operation.StorageFromId);

                    productInc = await db.Product.FirstOrDefaultAsync(i => i.Uid == operation.ProductId && i.StorageId == operation.StorageToId);

                    storageIdForInc = operation.StorageToId;
                }
                else
                {
                    // if we undoing operations, product come from To to From storage
                    productInc = await db.Product.FirstOrDefaultAsync(i => i.Uid == operation.ProductId && i.StorageId == operation.StorageFromId);

                    productDec = await db.Product.FirstOrDefaultAsync(i => i.Uid == operation.ProductId && i.StorageId == operation.StorageToId);

                    storageIdForInc = operation.StorageFromId;
                }

                IncreaseOrAddProduct(productInc, operation, storageIdForInc);
                DecreaseOrRemoveProduct(productDec, operation);

                await db.SaveChangesAsync();
            }

            // set transaction last updated date to current
            transaction.Date = DateTime.UtcNow;
            // and reverse open status
            transaction.IsOpen = !transaction.IsOpen;

            await UpdateDataModelAsync(transaction);
        }
コード例 #8
0
ファイル: TestsFixture.cs プロジェクト: 42ama/Cursed
        public static async Task ClearDatabase(CursedDataContext context)
        {
            await context.RecipeInheritance.ClearIfAny();

            await context.RecipeProductChanges.ClearIfAny();

            await context.Operation.ClearIfAny();

            await context.License.ClearIfAny();

            await context.TransactionBatch.ClearIfAny();

            await context.TechProcess.ClearIfAny();

            await context.Facility.ClearIfAny();

            await context.Product.ClearIfAny();

            await context.Recipe.ClearIfAny();

            await context.ProductCatalog.ClearIfAny();

            await context.Storage.ClearIfAny();

            await context.Company.ClearIfAny();

            await context.SaveChangesAsync();
        }