/// <summary>
        /// Turns a SpecProcessAssign into an entity along with all the options, but the options are NOT hydrated.
        /// </summary>
        public static SpecProcessAssign ToHydratedEntity(this SpecProcessAssignModel aSpecProcessAssignModel)
        {
            var result = aSpecProcessAssignModel.ToEntity();

            result.SpecProcessAssignOption = aSpecProcessAssignModel.SpecProcessAssignOptionModels.ToEntities().ToList();

            return(result);
        }
Пример #2
0
        public async Task <SpecProcessAssignModel> CopyAfterReview(SpecProcessAssignModel aSpecProcessAssignModel) //This will be the old SpecProcessAssignModel so the AssignId will need to be updated.  "Keep" on the front-end
        {
            using (var transaction = await Context.Database.BeginTransactionAsync())
            {
                await RemoveReviewNeeded(aSpecProcessAssignModel.SpecId, aSpecProcessAssignModel.SpecRevId, aSpecProcessAssignModel.SpecAssignId);

                var mostRecentSpecRevId    = (await Context.SpecificationRevision.Where(i => i.SpecId == aSpecProcessAssignModel.SpecId).OrderByDescending(i => i.SpecRevId).FirstOrDefaultAsync()).SpecRevId;
                var mostRecentProcessRevId = (await Context.ProcessRevision.Where(i => i.ProcessId == aSpecProcessAssignModel.ProcessId).OrderByDescending(i => i.ProcessRevId).FirstOrDefaultAsync()).ProcessRevId;

                aSpecProcessAssignModel.SpecRevId    = mostRecentSpecRevId;
                aSpecProcessAssignModel.ProcessRevId = mostRecentProcessRevId;

                //Pulls all assignments that have the same specId and specRevId (which will be the SPA "Family") as the assignment being copied.
                var specProcessAssignFamily = await Context.SpecProcessAssign.Where(i => i.SpecId == aSpecProcessAssignModel.SpecId &&
                                                                                    i.SpecRevId == mostRecentSpecRevId).ToListAsync();

                if (specProcessAssignFamily == null || !specProcessAssignFamily.Any()) //There aren't any previous assigns for this spec/spec rev
                {
                    aSpecProcessAssignModel.SpecAssignId = 2;
                    foreach (var option in aSpecProcessAssignModel.SpecProcessAssignOptionModels) //Update options for options
                    {
                        option.SpecAssignId = 2;
                    }
                }
                else //There are assign Ids already for this spec/spec rev
                {
                    var lastAssignIdUsed = specProcessAssignFamily.OrderByDescending(i => i.SpecAssignId).FirstOrDefault().SpecAssignId;
                    aSpecProcessAssignModel.SpecAssignId = (lastAssignIdUsed + 1);
                    if (aSpecProcessAssignModel.SpecProcessAssignOptionModels != null)
                    {
                        foreach (var option in aSpecProcessAssignModel.SpecProcessAssignOptionModels) //Update options for options
                        {
                            option.SpecAssignId = (lastAssignIdUsed + 1);
                        }
                    }
                }

                aSpecProcessAssignModel.Inactive       = false;
                aSpecProcessAssignModel.IsReviewNeeded = false;

                Context.SpecProcessAssign.Add(aSpecProcessAssignModel.ToEntity());
                await Context.SaveChangesAsync();

                await transaction.CommitAsync();

                return(aSpecProcessAssignModel);
            }
        }
Пример #3
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);
        }