Esempio n. 1
0
        public async Task <ActionResult> OnPost()
        {
            var optionModels = new List <SpecProcessAssignOptionModel>();

            if (ChoiceId1 != null)
            {
                optionModels.Add(new SpecProcessAssignOptionModel()
                {
                    SpecId        = SpecId,
                    SpecRevId     = SpecInternalRevId,
                    SubLevelSeqId = 1, //TODO: Should this be hard-coded to 1?
                    ChoiceSeqId   = (byte)ChoiceId1
                });
            }

            if (ChoiceId2 != null)
            {
                optionModels.Add(new SpecProcessAssignOptionModel()
                {
                    SpecId        = SpecId,
                    SpecRevId     = SpecInternalRevId,
                    SubLevelSeqId = 2, //TODO: Should this be hard-coded to 2?
                    ChoiceSeqId   = (byte)ChoiceId2
                });
            }

            if (ChoiceId3 != null)
            {
                optionModels.Add(new SpecProcessAssignOptionModel()
                {
                    SpecId        = SpecId,
                    SpecRevId     = SpecInternalRevId,
                    SubLevelSeqId = 3, //TODO: Should this be hard-coded to 3?
                    ChoiceSeqId   = (byte)ChoiceId3
                });
            }

            if (ChoiceId4 != null)
            {
                optionModels.Add(new SpecProcessAssignOptionModel()
                {
                    SpecId        = SpecId,
                    SpecRevId     = SpecInternalRevId,
                    SubLevelSeqId = 4, //TODO: Should this be hard-coded to 4?
                    ChoiceSeqId   = (byte)ChoiceId4
                });
            }

            if (ChoiceId5 != null)
            {
                optionModels.Add(new SpecProcessAssignOptionModel()
                {
                    SpecId        = SpecId,
                    SpecRevId     = SpecInternalRevId,
                    SubLevelSeqId = 5, //TODO: Should this be hard-coded to 5?
                    ChoiceSeqId   = (byte)ChoiceId5
                });
            }

            if (ChoiceId6 != null)
            {
                optionModels.Add(new SpecProcessAssignOptionModel()
                {
                    SpecId        = SpecId,
                    SpecRevId     = SpecInternalRevId,
                    SubLevelSeqId = 6, //TODO: Should this be hard-coded to 6?
                    ChoiceSeqId   = (byte)ChoiceId6
                });
            }

            var theSpecProcessAssignModel = new Armis.BusinessModels.QualityModels.Spec.SpecProcessAssignModel()
            {
                SpecId       = SpecId,
                SpecRevId    = SpecInternalRevId,
                CustomerId   = CustomerId,
                ProcessId    = ProcessId,
                ProcessRevId = ProcessRevId,
                SpecProcessAssignOptionModels = optionModels
            };

            var areChoicesUnique = await SpecProcessAssignDataAccess.VerifyUniqueChoices(SpecId, SpecInternalRevId, CustomerId ?? 0, optionModels);

            if (ModelState.IsValid && areChoicesUnique)
            {
                await SpecProcessAssignDataAccess.PostSpecProcessAssign(theSpecProcessAssignModel);

                return(RedirectToPage("/Quality/Specification/SpecProcessAssign", new { aMessage = "Specification-Process assignment saved successfully", isMessageGood = true }));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    Message = new PopUpMessageModel()
                    {
                        Text          = "Process is required",
                        IsMessageGood = false
                    };

                    await SetUpProperties();

                    return(Page());
                }
                else if (!areChoicesUnique)
                {
                    return(RedirectToPage("/Quality/Specification/SpecProcessAssign", new { aMessage = "Another Specificaiton-Process assignment has already been created with those options", isMessageGood = false }));
                }

                return(RedirectToPage("/Error", new { ExMessage = "An unknown error occured" }));
            }
        }