Exemplo n.º 1
0
        public async Task<tbSurveyQuestionItem> CreateNewItem(dtoSurveyQuestionItem item)
        {

            tbSurveyQuestionItem newItem = new tbSurveyQuestionItem();
            try
            {
                var itemCount = _db.tbSurveyQuestionItems.Where(x => x.QuestionId == item.QuestionId
                    && (x.IsActive ?? true) && !(x.IsDeleted ?? false)).Count();
                newItem.QuestionId = item.QuestionId;
                newItem.ItemDescription = item.ItemDescription;
                newItem.ItemOrder = item.ItemOrder != 0 ? item.ItemOrder : itemCount + 1;
                newItem.Score = item.Score;
                newItem.CreatedDate = DateTime.UtcNow;
                newItem.UpdatedDate = DateTime.UtcNow;
                newItem.IsActive = true;
                newItem.IsDeleted = false;

                _db.tbSurveyQuestionItems.Add(newItem);
                await _db.SaveChangesAsync();
            }
            catch (DataException dex)
            {
                throw new ApplicationException("Data error!", dex);
            }

            return newItem;
        }
Exemplo n.º 2
0
        public async Task<tbSurveyQuestionItem> GetQuestionItemByItemId(int itemId)
        {
            tbSurveyQuestionItem item = new tbSurveyQuestionItem();

            try
            {
                item = await _db.tbSurveyQuestionItems.FirstOrDefaultAsync(x => x.QuestionItemId == itemId
                    && (x.IsActive ?? true) && !(x.IsDeleted ?? false));
            }
            catch (DataException dex)
            {
                throw new ApplicationException("Data error!", dex);
            }

            return item;
        }