Ejemplo n.º 1
0
        public static tbSurvey ConverToTbSurvey(this dtoSurvey source, tbSurvey data = null)
        {
            if (data == null)
                data = new tbSurvey();

            if (source == null)
                return null;

            data.SurveyId = source.SurveyId;
            data.Title = source.Title;
            data.Slug = source.Slug;
            data.URLToken = source.URLToken;
            data.ShortDescription = source.ShortDesc;
            data.LongDescription = source.LongDesc;
            data.UserId = source.UserId;
            data.IsActive = source.IsActive;
            data.IsDeleted = source.IsDeleted;

            return data;
        }
Ejemplo n.º 2
0
        public async Task<tbSurvey> CreateNewSurvey(dtoSurvey survey)
        {
            tbSurvey newSurvey = new tbSurvey();

            try
            {
                newSurvey.Title = survey.Title;
                newSurvey.Slug = survey.Slug;
                newSurvey.URLToken = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Replace("=", "").Replace("/", "").Replace("+", "");
                newSurvey.UserId = survey.UserId;
                newSurvey.ShortDescription = survey.ShortDesc;
                newSurvey.LongDescription = survey.LongDesc;
                newSurvey.CreatedDate = DateTime.UtcNow;
                newSurvey.UpdatedDate = DateTime.UtcNow;
                newSurvey.IsActive = true;
                newSurvey.IsDeleted = false;

                _db.tbSurveys.Add(newSurvey);

                if (survey.dtoQuestions != null)
                {
                    if (survey.dtoQuestions.Count() > 0)
                    {
                        // do the question create
                        foreach (dtoSurveyQuestion question in survey.dtoQuestions)
                        {
                            question.SurveyId = newSurvey.SurveyId;
                            await CreateNewQuestion(question);
                        }
                    }
                }


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