Exemplo n.º 1
0
        public async Task<tbSurveyResult> CreateNewSurveyResult(dtoSurveyResult result)
        {
            tbSurveyResult newResult = new tbSurveyResult();

            try
            {
                newResult.MinScore = result.MinScore;
                newResult.MaxScore = result.MaxScore;
                newResult.SurveyId = result.SurveyId;
                newResult.Title = result.Title;
                newResult.Description = result.Description;
                newResult.CreatedDate = DateTime.UtcNow;
                newResult.UpdatedDate = DateTime.UtcNow;
                newResult.IsActive = true;
                newResult.IsDeleted = false;

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

            return newResult;
        }
Exemplo n.º 2
0
        public async Task<tbSurveyResult> UpdateSurveyResult(dtoSurveyResult result)
        {
            tbSurveyResult theResult = null;

            try
            {
                theResult = await _db.tbSurveyResults.FirstOrDefaultAsync(x => x.SurveyResultId == result.SurveyResultId
                      && (x.IsActive ?? true) && !(x.IsDeleted ?? false));

                if (theResult != null)
                {
                    theResult.MinScore = result.MinScore;
                    theResult.MaxScore = result.MaxScore;
                    theResult.SurveyId = result.SurveyId;
                    theResult.Title = result.Title;
                    theResult.Description = result.Description;
                    theResult.UpdatedDate = DateTime.UtcNow;

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

            return theResult;
        }
Exemplo n.º 3
0
        public async Task<IHttpActionResult> GetSurveyResultByResultId(int surveyId, int resultId)
        {
            dtoSurveyResult result = new dtoSurveyResult();

            try
            {
                result = await _yuyanSvc.GetSurveyResultByResultId(resultId);
            }
            catch (ApplicationException aex)
            {
                return BadRequest(aex.Message);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

            return Ok(result);
        }
Exemplo n.º 4
0
        public async Task<IHttpActionResult> UpdateResult(int surveyId, int resultId, [FromBody] dtoSurveyResult result)
        {
            dtoSurveyResult dtoResult = new dtoSurveyResult();

            try
            {
                result.SurveyId = surveyId;
                dtoResult = await _yuyanSvc.UpdateSurveyResult(result);
            }
            catch (ApplicationException aex)
            {
                return BadRequest(aex.Message);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

            return Ok(dtoResult);
        }
Exemplo n.º 5
0
        public static dtoSurveyResult ConvertToDtoSurveyResult(this tbSurveyResult source, dtoSurveyResult data = null) {
            if (data == null)
                data = new dtoSurveyResult();

            if (source == null)
                return null;

            data.SurveyResultId = source.SurveyResultId;
            data.MinScore = source.MinScore;
            data.MaxScore = source.MaxScore;
            data.SurveyId = source.SurveyId;
            data.Title = source.Title;
            data.Description = source.Description;

            return data;
        }