/// <summary>
        ///
        /// </summary>
        /// <param name="input">vstupní objekt</param>
        /// <returns>výstupní objekt</returns>
        public ModelCoreResult <CreateCampaignQuestionOutputModel> CreateCampaign(CreateCampaignQuestionInputModel input)
        {
            // zalozim result
            var result = new ModelCoreResult <CreateCampaignQuestionOutputModel>();

            using (var conn = GetConnection())
            {
                // parametry
                var param = new DynamicParameters();
                param.Add("ID_Login", input.ID_Login, dbType: System.Data.DbType.Guid);
                param.Add("ID_Campaign", input.ID_Campaign, dbType: System.Data.DbType.Int32);
                param.Add("DisplayName", input.DisplayName, dbType: System.Data.DbType.String);
                param.Add("Description", input.Description, dbType: System.Data.DbType.String);
                param.Add("ID", input.ID, dbType: System.Data.DbType.Int32, direction: System.Data.ParameterDirection.Output);
                try
                {
                    // volani stored proc
                    string proc = "VT_Question_NEW_Campaign";
                    LogQuery(proc, input);
                    conn.Query <CreateCampaignQuestionOutputModel>(proc, param: param, commandType: System.Data.CommandType.StoredProcedure).FirstOrDefault();
                    // vytazeni output parametru
                    result.Data = new CreateCampaignQuestionOutputModel
                    {
                        ID = param.Get <int>("ID"),
                    };
                }
                // kontrola validaci
                catch (SqlException e)
                {
                    TryValidation(e, result);
                }
            }

            return(result);
        }
Exemple #2
0
        public ModelCoreResult <ICollection <ListCampaignVoteOutputModel> > ListCampaign(ListCampaignVoteInputModel input)
        {
            var random = new Random(DateTime.Now.Millisecond);
            var result = new ModelCoreResult <ICollection <ListCampaignVoteOutputModel> >();
            var list   = new List <ListCampaignVoteOutputModel>();

            string question = "Testovací otázka";

            list.Add(new ListCampaignVoteOutputModel
            {
                ID_Question = 1,
                Question    = question,
                DisplayName = "Yes",
                Count       = random.Next(250),
            });

            list.Add(new ListCampaignVoteOutputModel
            {
                ID_Question = 1,
                Question    = question,
                DisplayName = "No",
                Count       = random.Next(250),
            });

            list.Add(new ListCampaignVoteOutputModel
            {
                ID_Question = 1,
                Question    = question,
                DisplayName = "Don't know",
                Count       = random.Next(250),
            });

            result.Data = list;
            return(result);
        }
        public ModelCoreResult <ICollection <ListCampaignVoteOutputModel> > ListCampaign(ListCampaignVoteInputModel input)
        {
            var result = new ModelCoreResult <ICollection <ListCampaignVoteOutputModel> >();
            var list   = new List <ListCampaignVoteOutputModel>();

            var    col      = GetCollections();
            string question = "Testovací otázka";

            list.Add(new ListCampaignVoteOutputModel
            {
                ID_Question = 1,
                Question    = question,
                DisplayName = "Yes",
                Count       = col.Count(x => x.Result == true)
            });

            list.Add(new ListCampaignVoteOutputModel
            {
                ID_Question = 1,
                Question    = question,
                DisplayName = "No",
                Count       = col.Count(x => x.Result == false)
            });

            list.Add(new ListCampaignVoteOutputModel
            {
                ID_Question = 1,
                Question    = question,
                DisplayName = "Don't know",
                Count       = col.Count(x => x.Result == null)
            });

            result.Data = list;
            return(result);
        }
Exemple #4
0
        public ModelCoreResult <CreateVoteOutputModel> Create(CreateVoteInputModel input)
        {
            var result = new ModelCoreResult <CreateVoteOutputModel>();

            var col = GetCollections();

            col.Add(new VoteModel
            {
                Uid    = input.UID,
                Result = input.Result
            });


            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Získání validací z výjímky
        /// </summary>
        /// <typeparam name="T">vystupni data</typeparam>
        /// <param name="e">vyjimka</param>
        /// <param name="result">result</param>
        protected virtual void TryValidation <T>(Exception e, ModelCoreResult <T> result) where T : class
        {
            if (Validation.IsValidatationResult(e))
            {
                result.ValidationMessages = Validation.GetMessages(e);
                Log.Warn(e, "DB Validation: {0}", e.Message);
            }
            else if (Validation.IsErrorResult(e))
            {
                result.ValidationMessages = Validation.GetErrorMessages(e);
                Log.Info(e, "DB system error: {0}", e.Message);

                throw new VoterException(result.ValidationMessages.FirstOrDefault().DisplayName, e);
            }
            else
            {
                result.Exception = e;
                Log.Error(e, "DB Error: {0}\n{1}", e.Message, e.StackTrace);

                throw new AccessDeniedException(e);
            }
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input">vstupní objekt</param>
        /// <returns>výstupní objekt</returns>
        public ModelCoreResult <DeleteCampaignOutputModel> Delete(DeleteCampaignInputModel input)
        {
            // zalozim result
            var result = new ModelCoreResult <DeleteCampaignOutputModel>();

            using (var conn = GetConnection())
            {
                try
                {
                    // volani stored proc
                    string proc  = "VT_Campaign_DEL";
                    var    param = new DynamicParameters(input);
                    LogQuery(proc, input);
                    result.Data = conn.Query <DeleteCampaignOutputModel>(proc, param: param, commandType: System.Data.CommandType.StoredProcedure).FirstOrDefault();
                }
                // kontrola validaci
                catch (SqlException e)
                {
                    TryValidation(e, result);
                }
            }

            return(result);
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input">vstupní objekt</param>
        /// <returns>kolekce výstupních objektů</returns>
        public ModelCoreResult <ICollection <ListVoteOutputModel> > List(ListVoteInputModel input)
        {
            // zalozim result
            var result = new ModelCoreResult <ICollection <ListVoteOutputModel> >();

            using (var conn = GetConnection())
            {
                try
                {
                    // volani stored proc
                    string proc  = "VT_Vote_ALL";
                    var    param = new DynamicParameters(input);
                    LogQuery(proc, input);
                    result.Data = conn.Query <ListVoteOutputModel>(proc, param: param, commandType: System.Data.CommandType.StoredProcedure).ToList();
                }
                // kontrola validaci
                catch (SqlException e)
                {
                    TryValidation(e, result);
                }
            }

            return(result);
        }