public async void UpdateTechProcess_AtInitializedDbTable_UpdatedTechProcessEqualExpectedTechProcess()
        {
            // arrange
            var techProcess = GetTechProcess();

            fixture.db.Add(techProcess);
            await fixture.db.SaveChangesAsync();

            var expected = new TechProcess
            {
                FacilityId    = techProcess.FacilityId,
                RecipeId      = techProcess.RecipeId,
                DayEfficiency = (decimal)78.9012
            };

            // act
            await logic.UpdateDataModelAsync(expected);

            // assert
            var actual = await fixture.db.TechProcess.FirstOrDefaultAsync(i => i.FacilityId == techProcess.FacilityId && i.RecipeId == techProcess.RecipeId);

            Assert.Equal(expected.FacilityId, actual.FacilityId);
            Assert.Equal(expected.RecipeId, actual.RecipeId);
            Assert.Equal(expected.DayEfficiency, actual.DayEfficiency);
        }
        /// <summary>
        /// Delete tech process.
        /// </summary>
        /// <param name="model">Model of tech process containing key information (FacilityId and RecipeId) to find tech process</param>
        public async Task RemoveDataModelAsync(TechProcess model)
        {
            var entity = await db.TechProcess.SingleAsync(i => i.RecipeId == model.RecipeId && i.FacilityId == model.FacilityId);

            db.TechProcess.Remove(entity);
            await db.SaveChangesAsync();
        }
        /// <summary>
        /// Update tech process.
        /// </summary>
        /// <param name="model">Updated company information</param>
        public async Task UpdateDataModelAsync(TechProcess model)
        {
            var currentModel = await db.TechProcess.FirstOrDefaultAsync(i => i.RecipeId == model.RecipeId && i.FacilityId == model.FacilityId);

            db.Entry(currentModel).CurrentValues.SetValues(model);
            await db.SaveChangesAsync();
        }
        /// <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);
        }
Example #5
0
        /// <summary>
        /// Checks if related entities exitst
        /// </summary>
        /// <param name="model">Technological process model to be validated</param>
        /// <param name="statusMessage">Error handler to which problem will be added</param>
        /// <returns>Status message with validaton information</returns>
        private async Task <IErrorHandler> CheckRelatedEntitiesExists(TechProcess model, IErrorHandler statusMessage)
        {
            // check if related facility exists
            if (await db.Facility.FirstOrDefaultAsync(i => i.Id == model.FacilityId) == null)
            {
                statusMessage.AddProblem(new Problem
                {
                    Entity          = "Facility.",
                    EntityKey       = (model.FacilityId).ToString(),
                    Message         = "Facility with this Id isn't found",
                    RedirectRoute   = FacilitiesRouting.Index,
                    UseKeyWithRoute = false
                });
            }

            // check if related product from catalog exists
            if (await db.Recipe.FirstOrDefaultAsync(i => i.Id == model.RecipeId) == null)
            {
                statusMessage.AddProblem(new Problem
                {
                    Entity          = "Recipe.",
                    EntityKey       = (model.RecipeId).ToString(),
                    Message         = "Recipe with this Id isn't found",
                    RedirectRoute   = RecipesRouting.Index,
                    UseKeyWithRoute = false
                });
            }

            return(statusMessage);
        }
Example #6
0
        private void frmTechProcessEdit_Load(object sender, EventArgs e)
        {
            if (_ProcId == null)
            {
                tp = _db.TechProcess.Add(new TechProcess());
            }
            else
            {
                tp = _db.TechProcess.Find(_ProcId);
            }

            TechProcessDS.DataSource = tp;
        }
Example #7
0
        /// <summary>
        /// Checks if technological process is valid, to be added
        /// </summary>
        /// <param name="model">Technological process model to be validated</param>
        /// <returns>Status message with validaton information</returns>
        public async Task <IErrorHandler> CheckAddDataModelAsync(TechProcess model)
        {
            var statusMessage = errorHandlerFactory.NewErrorHandler(new Problem
            {
                Entity          = "Technological procces.",
                EntityKey       = "",
                RedirectRoute   = HubRouting.Index,
                UseKeyWithRoute = false
            });

            await CheckNotExists((model.FacilityId, model.RecipeId), statusMessage);
            await CheckRelatedEntitiesExists(model, statusMessage);

            return(statusMessage);
        }
Example #8
0
        //public abstract void BuildProcessing(CableCommandGenerator generator);

        public override void Init()
        {
            base.Init();
            TechProcess.SetOperationParams(this);
        }
Example #9
0
        /// <summary>
        /// Checks if tech process is valid, to be updated
        /// </summary>
        /// <param name="model">Technological process model to be validated</param>
        /// <returns>Status message with validaton information</returns>
        public async Task <IErrorHandler> CheckUpdateDataModelAsync(TechProcess model)
        {
            var statusMessage = await CheckExists((model.FacilityId, model.RecipeId));

            return(await CheckRelatedEntitiesExists(model, statusMessage));
        }