Ejemplo n.º 1
0
        /// <summary>
        /// Delete QuestionClasifications and Save
        /// </summary>
        /// <param name="QuestionClasifications"></param>
        /// <param name="NTUser"></param>
        /// <returns></returns>
        internal async static Task <int> DeleteSaveAsync(QuestionClasifications QuestionClasifications, WindowsPrincipal NTUser)
        {
            int Count = 0;

            try
            {
                string TableName = QuestionClasifications.TableName;
                if (TableName == null)
                {
                    return(-1);
                }
                else if (TableName == typeof(Characteristic).Name)
                {
                    using (IQuestionCharacteristicRepository db = new QuestionCharacteristicRepository())
                    {
                        var Question = db.Find(QuestionClasifications.QuestionID, QuestionClasifications.ParameterID);
                        db.Delete(Question);
                        Count += await db.SaveAsync(NTUser);
                    }
                }
                else if (TableName == typeof(FamilyProduct).Name)
                {
                    using (IQuestionFamilyProductRepository db = new QuestionFamilyProductRepository())
                    {
                        var Question = db.Find(QuestionClasifications.QuestionID, QuestionClasifications.ParameterID);
                        db.Delete(Question);
                        Count += await db.SaveAsync(NTUser);
                    }
                }
                else if (TableName == typeof(Product).Name)
                {
                    using (IQuestionProductRepository db = new QuestionProductRepository())
                    {
                        var Question = db.Find(QuestionClasifications.QuestionID, QuestionClasifications.ParameterID);
                        db.Delete(Question);
                        Count += await db.SaveAsync(NTUser);
                    }
                }
                else if (TableName == typeof(Stakeholder).Name)
                {
                    using (IQuestionStakeholderRepository db = new QuestionStakeholderRepository())
                    {
                        var Question = db.Find(QuestionClasifications.QuestionID, QuestionClasifications.ParameterID);
                        db.Delete(Question);
                        Count += await db.SaveAsync(NTUser);
                    }
                }
                else if (TableName == typeof(Area).Name)
                {
                    using (IQuestionAreaRepository db = new QuestionAreaRepository())
                    {
                        var Question = db.Find(QuestionClasifications.QuestionID, QuestionClasifications.ParameterID);
                        db.Delete(Question);
                        Count += await db.SaveAsync(NTUser);
                    }
                }
            }
            catch (Exception ex)
            {
                Errors.Write(ex);
                Count = -1;
            }

            return(Count);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// add QuestionClasifications and Save
        /// </summary>
        /// <param name="QuestionClasifications"></param>
        /// <param name="NTUser"></param>
        /// <returns></returns>
        internal async static Task <int> AddSaveAsync(QuestionClasifications QuestionClasifications, WindowsPrincipal NTUser)
        {
            int Count = 0;

            try
            {
                string TableName = QuestionClasifications.TableName;
                if (TableName == null)
                {
                    return(-1);
                }
                else if (TableName == typeof(Characteristic).Name)
                {
                    using (IQuestionCharacteristicRepository db = new QuestionCharacteristicRepository())
                    {
                        var Question = new QuestionCharacteristic()
                        {
                            QuestionID       = QuestionClasifications.QuestionID,
                            CharacteristicID = QuestionClasifications.ParameterID,
                            AdminValue       = QuestionClasifications.AdminValue,
                            Comments         = QuestionClasifications.Comments
                        };
                        db.Add(Question);
                        Count += await db.SaveAsync(NTUser);

                        QuestionClasifications.RecordID = Question.QuestionCharacteristicID;
                    }
                }
                else if (TableName == typeof(FamilyProduct).Name)
                {
                    using (IQuestionFamilyProductRepository db = new QuestionFamilyProductRepository())
                    {
                        var Question = new QuestionFamilyProduct()
                        {
                            QuestionID      = QuestionClasifications.QuestionID,
                            FamilyProductID = QuestionClasifications.ParameterID,
                            AdminValue      = QuestionClasifications.AdminValue,
                            Comments        = QuestionClasifications.Comments
                        };
                        db.Add(Question);
                        Count += await db.SaveAsync(NTUser);

                        QuestionClasifications.RecordID = Question.QuestionFamilyProductID;
                    }
                }
                else if (TableName == typeof(Product).Name)
                {
                    using (IQuestionProductRepository db = new QuestionProductRepository())
                    {
                        var Question = new QuestionProduct()
                        {
                            QuestionID = QuestionClasifications.QuestionID,
                            ProductID  = QuestionClasifications.ParameterID,
                            AdminValue = QuestionClasifications.AdminValue,
                            Comments   = QuestionClasifications.Comments
                        };
                        db.Add(Question);
                        Count += await db.SaveAsync(NTUser);

                        QuestionClasifications.RecordID = Question.QuestionProductID;
                    }
                }
                else if (TableName == typeof(Stakeholder).Name)
                {
                    using (IQuestionStakeholderRepository db = new QuestionStakeholderRepository())
                    {
                        var Question = new QuestionStakeholder()
                        {
                            QuestionID    = QuestionClasifications.QuestionID,
                            StakeholderID = QuestionClasifications.ParameterID,
                            AdminValue    = QuestionClasifications.AdminValue,
                            Comments      = QuestionClasifications.Comments
                        };
                        db.Add(Question);
                        Count += await db.SaveAsync(NTUser);

                        QuestionClasifications.RecordID = Question.QuestionStakeholderID;
                    }
                }
                else if (TableName == typeof(Area).Name)
                {
                    using (IQuestionAreaRepository db = new QuestionAreaRepository())
                    {
                        var Question = new QuestionArea()
                        {
                            QuestionID = QuestionClasifications.QuestionID,
                            AreaID     = QuestionClasifications.ParameterID,
                            AdminValue = QuestionClasifications.AdminValue,
                            Comments   = QuestionClasifications.Comments
                        };
                        db.Add(Question);
                        Count += await db.SaveAsync(NTUser);

                        QuestionClasifications.RecordID = Question.QuestionAreaID;
                    }
                }
            }
            catch (Exception ex)
            {
                Errors.Write(ex);
                Count = -1;
            }

            return(Count);
        }