Example #1
0
        public async Task<IHttpActionResult> GetSurveyByURLToken(string urltoken)
        {
            dtoSurvey dtoSurvey = new dtoSurvey();

            try
            {
                dtoSurvey = await _yuyanSvc.GetSurveyByURLToken(urltoken);
                if (dtoSurvey == null)
                    return NotFound();

                dtoSurveyShare newShare = new dtoSurveyShare()
                {
                    SurveyId = dtoSurvey.SurveyId,
                    IPAddress = GetClientIp()
                };

                await _yuyanSvc.AddSurveyShare(newShare);
            }
            catch (ApplicationException aex)
            {
                return BadRequest(aex.Message);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

            return Ok(dtoSurvey);
        }
Example #2
0
        public async Task<tbSurveyShare> SaveSurveyShare(dtoSurveyShare surveyShare)
        {
            tbSurveyShare sShare = new tbSurveyShare();

            try
            {
                sShare.SurveyId = surveyShare.SurveyId;
                sShare.IPAddress = surveyShare.IPAddress;
                sShare.VisitedDate = DateTime.UtcNow;

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

            return sShare;
        }
Example #3
0
        public static dtoSurveyShare ConvertToDtoSurveyShare(this tbSurveyShare source, dtoSurveyShare data = null)
        {
            if (data == null)
                data = new dtoSurveyShare();

            if (source == null)
                return null;

            data.SurveyShareId = source.SurveyShareId;
            data.SurveyId = source.SurveyId;
            data.IPAddress = source.IPAddress;
            data.VisitedDate = source.VisitedDate;

            return data;
        }