示例#1
0
        //CREATE
        public async Task <SamplePlanModel> CreateSamplePlan(SamplePlanModel aSamplePlan)
        {
            using (var transaction = await Context.Database.BeginTransactionAsync())
            {
                var newSamplePlanId = (await Context.SamplePlanHead.MaxAsync(s => s.SamplePlanId)) + 1;

                await Context.SamplePlanHead.AddAsync(aSamplePlan.ToEntity(newSamplePlanId));

                await Context.SamplePlanLevel.AddRangeAsync(aSamplePlan.SamplePlanLevelModels.ToEntities(newSamplePlanId));

                var tempSamplePlanRejectEntities = new List <SamplePlanReject>();
                foreach (var levelModel in aSamplePlan.SamplePlanLevelModels)
                {
                    await Context.AddRangeAsync(levelModel.SamplePlanRejectModels.ToEntities(newSamplePlanId));
                }

                await Context.SaveChangesAsync();

                await transaction.CommitAsync();

                //Goes back to the database and returns the fully hydrated Sample Plan it just created.  This is done so the user on the front-end can verify that the data got into the database correctly.
                return((await Context.SamplePlanHead.Where(i => i.SamplePlanId == newSamplePlanId)
                        .Include(h => h.SamplePlanLevel)
                        .ThenInclude(l => l.SamplePlanReject)
                        .ThenInclude(r => r.InspectTest).FirstOrDefaultAsync()).ToHydratedModel());;
            }
        }
示例#2
0
        public async Task <ActionResult <SamplePlanModel> > CreateHydratedSamplePlan(SamplePlanModel aSamplePlanModel) //ToDo: Create hydrated? Does that make sense?
        {
            try
            {
                var data = await SamplePlanService.CreateSamplePlan(aSamplePlanModel);

                return(Ok(JsonSerializer.Serialize(data)));
            }
            catch (Exception ex)
            {
                _logger.LogError("SamplePlanController.CreateHydratedSamplePlan(SamplePlanModel aSamplePlanModel) Not able to create sample plan {samplePlan}. | Message: {exMessage} | StackTrace: {stackTrace}", JsonSerializer.Serialize(aSamplePlanModel), ex.Message, ex.StackTrace);
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> OnPost()
        {
            if (!(await SamplePlanDataAccess.CheckIfNameIsUnique(SamplePlanName)))
            {
                Message = new PopUpMessageModel()
                {
                    IsMessageGood = false,
                    Text          = "A sameple plan with that name already exists."
                };
                return(Page());
            }

            var newSamplePlan = new SamplePlanModel()
            {
                PlanName    = SamplePlanName,
                Description = SamplePlanDescription
            };
            var tempLevelModelList = new List <SamplePlanLevelModel>();

            for (int i = 1; i <= AmountOfLevels; i++)
            {
                var fromValue = int.Parse(HttpContext.Request.Form["inputNumOfPartsFrom" + i]);
                int toValue;
                if (i == AmountOfLevels)
                {
                    toValue = int.MaxValue;
                }
                else
                {
                    toValue = int.Parse(HttpContext.Request.Form["inputNumOfPartsTo" + i]);
                }
                var newSamplePlanLevel = new SamplePlanLevelModel()
                {
                    SamplePlanLevelId = i,
                    FromQty           = fromValue,
                    ToQty             = toValue
                };

                var tempRejectModelList = new List <SamplePlanRejectModel>();

                for (int j = 1; j <= AmountOfTests; j++)
                {
                    var sampleQty  = int.Parse(HttpContext.Request.Form["inputSampleNum" + j + "-" + i]);
                    var rejectQty  = int.Parse(HttpContext.Request.Form["inputRejectNum" + j + "-" + i]);
                    var testTypeId = short.Parse(HttpContext.Request.Form["selectTestType" + j]);

                    var newSamplePlanReject = new SamplePlanRejectModel()
                    {
                        SamplePlanLevelId = i,
                        SampleQty         = sampleQty,
                        RejectAllowQty    = rejectQty,
                        InspectTestTypeId = testTypeId
                    };

                    tempRejectModelList.Add(newSamplePlanReject);
                }

                newSamplePlanLevel.SamplePlanRejectModels = tempRejectModelList;

                tempLevelModelList.Add(newSamplePlanLevel);
            }

            newSamplePlan.SamplePlanLevelModels = tempLevelModelList;

            await SamplePlanDataAccess.CreateNewSamplePlan(newSamplePlan);

            return(RedirectToPage("/Quality/Inspection/SamplePlanEntry", new { aMessage = "Sample Plan created successfully", isMessageGood = true }));
        }
示例#4
0
 public async Task <SamplePlanModel> CreateNewSamplePlan(SamplePlanModel aSamplePlanModel)
 {
     return(await DataAccessGeneric.HttpPostRequest <SamplePlanModel>(Config["APIAddress"] + "api/SamplePlan/CreateHydratedSamplePlan/", aSamplePlanModel, _httpContextAccessor.HttpContext));
 }