/// <summary>
        /// Creates Survey
        /// </summary>
        /// <param name="surveyDto"></param>
        /// <returns></returns>
        public OperationResult <ISurveyDTO> CreateSurvey(ISurveyDTO surveyDto)
        {
            OperationResult <ISurveyDTO> operationResult = null;

            try
            {
                var surveyDac = (ISurveyDAC)DACFactory.Instance.Create(DACType.Survey);

                var resultDto = surveyDac.CreateSurvey(surveyDto);
                operationResult = resultDto != null
                                                      ? OperationResult <ISurveyDTO> .CreateSuccessResult(surveyDto)
                                                      : OperationResult <ISurveyDTO> .CreateFailureResult(
                    ResourceUtility.GetCaptionFor(
                        ResourceConstants.Survey.ErrorMessages.FailedToCreateSurvey));
            }
            catch (DACException dacEx)
            {
                operationResult = OperationResult <ISurveyDTO> .CreateErrorResult(dacEx.Message, dacEx.StackTrace);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                operationResult = OperationResult <ISurveyDTO> .CreateErrorResult(ex.Message, ex.StackTrace);
            }
            return(operationResult);
        }
Exemple #2
0
        /// <summary>
        /// Gets the survey by identifier.
        /// </summary>
        /// <param name="surveyId">The Survey identifier.</param>
        /// <returns>ISurveyDTO.</returns>
        /// <exception cref="DACException">Error while fetching the Survey detail.</exception>
        public ISurveyDTO GetSurveyById(int surveyId)
        {
            ISurveyDTO surveyDto = null;

            try
            {
                using (var dbContext = new SSEntities())
                {
                    var surveyEntity = (from Survey in dbContext.Surveys
                                        where Survey.Id == surveyId
                                        select Survey).SingleOrDefault();

                    if (surveyEntity != null)
                    {
                        surveyDto = (ISurveyDTO)DTOFactory.Instance.Create(DTOType.Survey);
                        EntityConverter.FillDTOFromEntity(surveyEntity, surveyDto);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException("Error while fetching the Survey detail.", ex);
            }

            return(surveyDto);
        }
Exemple #3
0
        /// <summary>
        /// Updates a survey
        /// </summary>
        /// <param name="surveyDto"></param>
        /// <returns></returns>
        public ISurveyDTO UpdateSurvey(ISurveyDTO surveyDto)
        {
            try
            {
                if (surveyDto != null)
                {
                    using (var dbContext = new SSEntities())
                    {
                        var surveyEntity = (from qs in dbContext.Surveys
                                            where qs.Id == surveyDto.Id
                                            select qs).Single();

                        if (surveyEntity != null)
                        {
                            EntityConverter.FillEntityFromDTO(surveyDto, surveyEntity);
                        }

                        if (dbContext.SaveChanges() > 0)
                        {
                            surveyDto.Id = surveyEntity.Id;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException("Error while updating the Survey.", ex);
            }
            return(surveyDto);
        }
Exemple #4
0
        /// <summary>
        /// Gets all surveys
        /// </summary>
        /// <param name="surveyId">The Survey identifier.</param>
        /// <returns>IList<ISurveyDTO>.</returns>
        /// <exception cref="DACException">Error while fetching the Survey detail.</exception>
        public IList <ISurveyDTO> GetAllSurveys()
        {
            IList <ISurveyDTO> surveyDtos = new List <ISurveyDTO>();

            try
            {
                using (var dbContext = new SSEntities())
                {
                    var surveyEntities = (from Survey in dbContext.Surveys
                                          select Survey).ToList();

                    ISurveyDTO surveyDto = null;
                    foreach (var surveyEntity in surveyEntities)
                    {
                        surveyDto = (ISurveyDTO)DTOFactory.Instance.Create(DTOType.Survey);
                        EntityConverter.FillDTOFromEntity(surveyEntity, surveyDto);
                        surveyDtos.Add(surveyDto);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException("Error while fetching the Survey detail.", ex);
            }

            return(surveyDtos);
        }
Exemple #5
0
 /// <summary>
 /// Creates a survey
 /// </summary>
 /// <param name="surveyDto"></param>
 /// <returns></returns>
 public ISurveyDTO CreateSurvey(ISurveyDTO surveyDTO)
 {
     try
     {
         if (surveyDTO != null)
         {
             using (var context = new SSEntities())
             {
                 var surveyEntity = new Survey();
                 EntityConverter.FillEntityFromDTO(surveyDTO, surveyEntity);
                 context.Surveys.Add(surveyEntity);
                 if (context.SaveChanges() > 0)
                 {
                     surveyDTO.Id = surveyEntity.Id;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ExceptionManager.HandleException(ex);
         throw new DACException("Error while creating the Survey.", ex);
     }
     return(surveyDTO);
 }