Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public async Task PutQuestionTemplateAsync(EquityQuestionTemplateContract model)
        {
            var updatedQuestion = await Context.EquityQuestionTemplates.FindAsync(model.Id);

            if (updatedQuestion == null)
            {
                throw new CannotFindIdException("questionTemplate", model.Id);
            }

            var editedQuestion = EquityMapper.QuestionTemplateContractToEntity(model);

            Context.Entry(updatedQuestion).CurrentValues.SetValues(editedQuestion);
            Context.Entry(updatedQuestion).State = EntityState.Modified;

            if (await Context.SaveChangesAsync() <= 0)
            {
                throw new CannotSaveToDatabaseException("questionTemplate");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// post new equity question template
        /// </summary>
        /// /// <param EquityQuestionTemplateContract="model"></param>
        /// <returns></returns>
        public async Task <int> PostQuestionTemplateAsync(EquityQuestionTemplateContract model)
        {
            if (Context.EquityQuestionTemplates.Find(model.Id) != null)
            {
                throw new EntityConflictException("questionTemplate", model.Id);
            }

            var newQuestion = EquityMapper.QuestionTemplateContractToEntity(model);

            Context.EquityQuestionTemplates.Add(newQuestion);
            Context.Entry(newQuestion).State = EntityState.Added;

            var saved = await Context.SaveChangesAsync();

            if (saved <= 0)
            {
                throw new CannotSaveToDatabaseException("questionTemplate");
            }
            var questionId = newQuestion.Id;

            return(questionId);
        }