コード例 #1
0
        //CREATE
        public async Task <PartModel> CreatePart(PartModel aPart)
        {
            var entityToAdd = aPart.ToEntity();

            entityToAdd.PartId = (await Context.Part.MaxAsync(i => i.PartId)) + 1;

            Context.Part.Add(entityToAdd);

            await Context.SaveChangesAsync();

            return(entityToAdd.ToModel());
        }
コード例 #2
0
ファイル: OperationService.cs プロジェクト: JosephKigin/Armis
        //Post
        public async Task <OperationModel> AddOperation(OperationModel anOperation)
        {
            var theOperEntityToAdd = anOperation.ToEntity();

            var theMostRecentId = await context.Operation.MaxAsync(i => i.OperationId);

            var theOperationGroup = await context.OperationGroup.FirstOrDefaultAsync(i => i.OperGroupId == anOperation.Group.Id);

            theOperEntityToAdd.OperationId = theMostRecentId + 1;
            theOperEntityToAdd.OperGroup   = theOperationGroup;
            context.Add(theOperEntityToAdd);
            await context.SaveChangesAsync();

            return(theOperEntityToAdd.ToModel());
        }
コード例 #3
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());;
            }
        }
コード例 #4
0
ファイル: ProcessService.cs プロジェクト: JosephKigin/Armis
        //Create
        public async Task <ProcessModel> CreateNewProcess(ProcessModel process)
        {
            var processEntity = process.ToEntity();

            var lastUsedId = await context.Process.MaxAsync(i => i.ProcessId);

            processEntity.ProcessId = lastUsedId + 1;

            if (process.Revisions.Count() > 1)
            {
                throw new Exception("Cannot save a process and multiple revisions at once");
            }

            var theRevision = process.Revisions.FirstOrDefault();

            theRevision.DateTimeCreated = DateTime.Now;
            theRevision.ProcessId       = processEntity.ProcessId;
            theRevision.ProcessRevId    = 1; //This is the first revision of a new process, so it should always be 1.
            theRevision.RevStatusId     = 2; //The revisions will start as UNLOCKED.

            processEntity.ProcessRevision.Add(theRevision.ToEntity());

            context.Process.Add(processEntity);
            await context.SaveChangesAsync();

            return(processEntity.ToHydratedModel());
        }
コード例 #5
0
ファイル: StepService.cs プロジェクト: JosephKigin/Armis
        //CREATE
        public async Task <StepModel> CreateStep(StepModel aStepModel)
        {
            if (aStepModel == null)
            {
                throw new NullReferenceException("No step model was given.");
            }

            var theLastStepIdUsed = await Context.Step.MaxAsync(i => i.StepId);

            aStepModel.StepId = theLastStepIdUsed + 1;

            var theStepEntity = aStepModel.ToEntity();

            Context.Step.Add(theStepEntity);
            await Context.SaveChangesAsync();

            return(aStepModel);
        }
コード例 #6
0
        //Create
        public async Task <InspectTestTypeModel> CreateInspectTestType(InspectTestTypeModel anInspectTestTypeModel)
        {
            var lastInspectTestId = await Context.InspectTestType.MaxAsync(i => i.InspectTestId);

            anInspectTestTypeModel.InspectTestId = (Int16)(lastInspectTestId + 1);

            Context.InspectTestType.Add(anInspectTestTypeModel.ToEntity());

            await Context.SaveChangesAsync();

            return(anInspectTestTypeModel);
        }
コード例 #7
0
        //CREATE
        public async Task <SpecProcessAssignModel> PostSpecProcessAssign(SpecProcessAssignModel aSpecProcessAssignModel) //The model that gets passed in is returned with an updated SpecAssignId
        {
            int theNewSpecAssignId;
            var theCurrenSpecProcessAssigns = await Context.SpecProcessAssign.Where(i => i.SpecId == aSpecProcessAssignModel.SpecId && i.SpecRevId == aSpecProcessAssignModel.SpecRevId).ToListAsync();

            if (theCurrenSpecProcessAssigns != null && theCurrenSpecProcessAssigns.Any())
            {
                theNewSpecAssignId = (theCurrenSpecProcessAssigns.OrderByDescending(i => i.SpecAssignId).FirstOrDefault().SpecAssignId) + 1;
            }
            else
            {
                theNewSpecAssignId = 2;
            }                                //Spec assign needs to start at 2 because 1 is saved as default TODO: spec assign 1 was not created by the time the website got here!!!  THIS ELSE SHOULD NEVER HAPPEN!!!!!!!!!!!!!!!!
            aSpecProcessAssignModel.SpecAssignId = theNewSpecAssignId;
            var theSpecProcessAssignEntity = aSpecProcessAssignModel.ToEntity();

            Context.SpecProcessAssign.Add(theSpecProcessAssignEntity);
            await Context.SaveChangesAsync();

            return(aSpecProcessAssignModel);
        }
コード例 #8
0
        public async Task <MaterialSeriesModel> CreateMaterialSeries(MaterialSeriesModel aMaterialSeriesModel)
        {
            var entityToAdd = aMaterialSeriesModel.ToEntity();

            var lastUsedId = await Context.MaterialSeries.MaxAsync(i => i.MaterialSeriesId);

            entityToAdd.MaterialSeriesId = (lastUsedId + 1);

            Context.MaterialSeries.Add(entityToAdd);
            await Context.SaveChangesAsync();

            return(entityToAdd.ToModel());
        }
コード例 #9
0
        public async Task <MaterialAlloyModel> CreateMaterialAlloy(MaterialAlloyModel aMaterialAlloyModel)
        {
            var entityToAdd = aMaterialAlloyModel.ToEntity();

            var lastIdUsed = await Context.MaterialAlloy.MaxAsync(i => i.MaterialAlloyId);

            entityToAdd.MaterialAlloyId = (lastIdUsed + 1);

            Context.MaterialAlloy.Add(entityToAdd);
            await Context.SaveChangesAsync();

            return(entityToAdd.ToModel());
        }
コード例 #10
0
        public async Task <HardnessModel> CreateHardness(HardnessModel aHardnessModel)
        {
            var entityToAdd = aHardnessModel.ToEntity();

            int lastIdUsed = 1;

            if (Context.Hardness.Any())
            {
                lastIdUsed = await Context.Hardness.MaxAsync(i => i.HardnessId);
            }

            entityToAdd.HardnessId = (lastIdUsed + 1);

            Context.Hardness.Add(entityToAdd);
            await Context.SaveChangesAsync();

            return(entityToAdd.ToModel());
        }
コード例 #11
0
        public async Task <OrderReceivedModel> CreateOrderReceived(OrderReceivedModel anOrderReceivedModel)
        {
            var entity            = anOrderReceivedModel.ToEntity();
            var previousReceiveds = await Context.OrderReceived.Where(i => i.OrderId == anOrderReceivedModel.OrderId).ToListAsync();

            if (previousReceiveds == null || !previousReceiveds.Any())
            {
                entity.ReceivedNum = 1;
            }
            else
            {
                entity.ReceivedNum = (short)(previousReceiveds.Max(i => i.ReceivedNum) + 1);
            }

            Context.OrderReceived.Add(entity);
            await Context.SaveChangesAsync();

            return(entity.ToModel());
        }
コード例 #12
0
ファイル: OrderHeadService.cs プロジェクト: JosephKigin/Armis
        //Post
        public async Task <OrderHeadModel> PostOrderHead(OrderHeadModel anOrderHeadModel)
        {
            var theOrderHeadId = await Context.OrderHead.MaxAsync(i => i.OrderId) + 1;

            anOrderHeadModel.OrderId = theOrderHeadId;

            foreach (var orderDetail in anOrderHeadModel.OrderDetails) //Assigns the order id to all the orderDetails
            {
                orderDetail.OrderId = theOrderHeadId;
            }

            Context.Add(anOrderHeadModel.ToEntity());

            Context.AddRange(anOrderHeadModel.OrderDetails.ToEntities());

            await Context.SaveChangesAsync();

            return(anOrderHeadModel);
        }
コード例 #13
0
        public async Task <int> CreateNewSpec(SpecModel aSpecModel)
        {
            using (var transaction = await context.Database.BeginTransactionAsync())
            {
                var theNewSpecId = await context.Specification.MaxAsync(i => i.SpecId) + 1;

                short theNewRevId = 10; //All new specs start with a revId of 10
                if (aSpecModel.SpecRevModels == null)
                {
                    throw new Exception("Cannot create a new Specification without a Revision.");
                }
                if (aSpecModel.SpecRevModels.Count() > 1)
                {
                    throw new Exception("Cannot save a new Specification with multiple revisions; only one revision is allowed.");
                }
                var theSpecRevModel     = aSpecModel.SpecRevModels.FirstOrDefault(); //Only ONE revision can be passed in.
                var theSubLevelEntities = theSpecRevModel.SubLevels.ToEntities(theNewSpecId, theNewRevId);

                await context.Specification.AddAsync(aSpecModel.ToEntity(theNewSpecId));

                await context.SpecificationRevision.AddAsync(theSpecRevModel.ToEntity(theNewSpecId, theNewRevId));

                await context.SpecSubLevel.AddRangeAsync(theSubLevelEntities);

                foreach (var subLevel in theSpecRevModel.SubLevels)
                {
                    var choicesToAdd = subLevel.Choices.ToEntities(theNewSpecId, theNewRevId).ToList();
                    foreach (var choice in choicesToAdd)
                    {
                        choice.OnlyValidForChoice = null;
                    }
                    await context.AddRangeAsync(choicesToAdd); //Problem is here and it happens immediatly!!! <--- TODO?
                }

                await context.SaveChangesAsync();

                //Updating entities with dependents
                foreach (var subLevel in theSpecRevModel.SubLevels)
                {
                    var originalChoices = subLevel.Choices.ToList();
                    var choicesToUpdate = await context.SpecChoice.Where(i => i.SpecId == theNewSpecId && i.SpecRevId == theNewRevId && i.SubLevelSeqId == subLevel.LevelSeq).ToListAsync();

                    foreach (var choice in choicesToUpdate)
                    {
                        choice.OnlyValidForChoice = originalChoices.FirstOrDefault(i => i.ChoiceSeqId == choice.ChoiceSeqId).OnlyValidForChoiceId;
                    }

                    context.UpdateRange(choicesToUpdate);
                    await context.SaveChangesAsync();
                }


                //Default choice in the subLevel has to be null when saving the data for the first time to prevent an issue with circular dependency.  They must be updated after the first save.
                foreach (var subLevel in theSubLevelEntities)
                {
                    subLevel.DefaultChoice = theSpecRevModel.SubLevels.FirstOrDefault(i => i.LevelSeq == subLevel.SubLevelSeqId).DefaultChoice;
                }

                context.UpdateRange(theSubLevelEntities);

                await context.SaveChangesAsync();

                await transaction.CommitAsync();

                return(theNewSpecId);
            }
        }