コード例 #1
0
        /// <summary>
        /// Gets equity stories by id
        /// </summary>
        /// <param id="id"></param>
        /// <returns></returns>
        public async Task <EquityStoryContract> GetStoryByIdAsync(int id)
        {
            var story = await Context.EquityStories.FirstOrDefaultAsync(x => x.Id == id);

            if (story == null)
            {
                throw new CannotFindIdException("story", id);
            }

            var result = EquityMapper.EquityStoryEntityToContract(story);

            return(result);
        }
コード例 #2
0
        //Equity Questions CRUD Operations
        #region Equity Question Templates
        #region GET
        /// <summary>
        /// Gets equity question by id
        /// </summary>
        /// <param id="id"></param>
        /// <returns></returns>
        public async Task <EquityQuestionTemplateContract> GetQuestionTemplateByIdAsync(int id)
        {
            var question = await Context.EquityQuestionTemplates.FirstOrDefaultAsync(x => x.Id == id);

            if (question == null)
            {
                throw new CannotFindIdException("questionTemplate", id);
            }

            var result = EquityMapper.QuestionTemplateEntityToContract(question);

            return(result);
        }
コード例 #3
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");
            }
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public async Task PutStoryAsync(EquityStoryContract model)
        {
            var updatedStory = await Context.EquityStories.FindAsync(model.Id);

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

            var editedStory = EquityMapper.EquityContractToEntity(model);

            Context.Entry(updatedStory).CurrentValues.SetValues(editedStory);
            Context.Entry(updatedStory).State = EntityState.Modified;

            if (await Context.SaveChangesAsync() <= 0)
            {
                throw new CannotSaveToDatabaseException("Story");
            }
        }
コード例 #5
0
        /// <summary>
        /// post new equity story
        /// </summary>
        /// /// <param EquityContract="model"></param>
        /// <returns></returns>
        public async Task <int> PostStoryAsync(EquityStoryContract model)
        {
            if (Context.EquityStories.Find(model.Id) != null)
            {
                throw new EntityConflictException("story", model.Id);
            }

            var newStory = EquityMapper.EquityContractToEntity(model);

            Context.EquityStories.Add(newStory);
            Context.Entry(newStory).State = EntityState.Added;

            var saved = await Context.SaveChangesAsync();

            if (saved <= 0)
            {
                throw new CannotSaveToDatabaseException("story");
            }
            var storyId = newStory.Id;

            return(storyId);
        }
コード例 #6
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);
        }