public static dtoSurveyQuestionItem ConvertToDtoSurveyQuestionItem(this tbSurveyQuestionItem source, dtoSurveyQuestionItem data = null) { if (data == null) data = new dtoSurveyQuestionItem(); if (source == null) return null; data.QuestionItemId = source.QuestionItemId; data.QuestionId = source.QuestionId; data.ItemDescription = source.ItemDescription; data.ItemOrder = source.ItemOrder; data.Score = source.Score; data.GotoQuestionId = source.GotoQuestionId; data.IsActive = source.IsActive; data.IsDeleted = source.IsDeleted; return data; }
public async Task TestRepo_DeleteItem() { using (YuYanDBContext db = new YuYanDBContext()) using (YuYanDBRepository repos = new YuYanDBRepository(db)) { dtoSurveyQuestionItem newItem = new dtoSurveyQuestionItem(); await repos.DeleteItem(4); } }
public async Task TestRepo_UpdateItem() { using (YuYanDBContext db = new YuYanDBContext()) using (YuYanDBRepository repos = new YuYanDBRepository(db)) { dtoSurveyQuestionItem newItem = new dtoSurveyQuestionItem(); newItem.QuestionItemId = 7; newItem.ItemDescription = "The ddddd chdfdsfsdsfoice"; var obj = await repos.UpdateItem(newItem); Assert.IsNotNull(obj); } }
public async Task TestRepo_CreateItem() { using (YuYanDBContext db = new YuYanDBContext()) using (YuYanDBRepository repos = new YuYanDBRepository(db)) { dtoSurveyQuestionItem newItem = new dtoSurveyQuestionItem(); newItem.QuestionId = 1; newItem.ItemDescription = "The third choice"; var obj = await repos.CreateNewItem(newItem); Assert.IsNotNull(obj); } }
public async Task<tbSurveyQuestionItem> UpdateItem(dtoSurveyQuestionItem item) { tbSurveyQuestionItem theItem = null; try { theItem = await _db.tbSurveyQuestionItems.FirstOrDefaultAsync(x => x.QuestionItemId == item.QuestionItemId && (x.IsActive ?? true) && !(x.IsDeleted ?? false)); if (theItem != null) { theItem.ItemDescription = item.ItemDescription; theItem.ItemOrder = item.ItemOrder; theItem.Score = item.Score; theItem.UpdatedDate = DateTime.UtcNow; await _db.SaveChangesAsync(); } } catch (DataException dex) { throw new ApplicationException("Data error!", dex); } return theItem; }
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; }
public async Task<IHttpActionResult> UpdateItem(int surveyId, int questionId, int itemId, [FromBody] dtoSurveyQuestionItem item) { dtoSurveyQuestionItem dtoItem = new dtoSurveyQuestionItem(); try { item.QuestionId = questionId; dtoItem = await _yuyanSvc.UpdateSurveyQuestionItem(item); } catch (ApplicationException aex) { return BadRequest(aex.Message); } catch (Exception ex) { return InternalServerError(ex); } return Ok(dtoItem); }
public async Task<IHttpActionResult> GetItemByItemId(int surveyid, int questionid, int itemId) { dtoSurveyQuestionItem item = new dtoSurveyQuestionItem(); try { item = await _yuyanSvc.GetQuestionItemByItemId(itemId); } catch (ApplicationException aex) { return BadRequest(aex.Message); } catch (Exception ex) { return InternalServerError(ex); } return Ok(item); }