예제 #1
0
        public ApiResponse <ParticipantApiModel> CreateParticipant(ParticipantApiModel participantApiModel)
        {
            var response        = new ApiResponse <ParticipantApiModel>();
            var participantData = _context.Participants
                                  .Where(x => x.Email.ToLower() == participantApiModel.Email.ToLower() && x.IsActive).FirstOrDefault();

            if (participantData != null)
            {
                response.IsSucceeded = true;
                response.Result      = participantData.ToParticipantApiModel();
            }
            else
            {
                var participant = new Participant
                {
                    Name        = participantApiModel.Name,
                    DateOfBirth = participantApiModel.DateOfBirth,
                    Email       = participantApiModel.Email,
                    IsActive    = true
                };
                _context.Participants.Add(participant);
                int rowAffective = _context.SaveChanges();

                response.IsSucceeded = rowAffective > 0;
                response.Result      = response.IsSucceeded ? participant.ToParticipantApiModel() : null;
            }
            return(response);
        }
예제 #2
0
        public Task CreateQuestion(QuestionApiModel question)
        {
            Question questionModel = question.ToQuestion();

            using (DbContextTransaction dbTran = _context.Database.BeginTransaction())
            {
                try
                {
                    _context.Questions.Add(questionModel);
                    _context.SaveChanges();

                    var options = question.Options?.Select(x => x.ToOption(questionModel.Id));
                    _context.Options.AddRange(options);
                    _context.SaveChanges();
                    dbTran.Commit();
                }
                catch (DbEntityValidationException ex)
                {
                    dbTran.Rollback();
                    throw;
                }
            }

            return(Task.FromResult(0));
        }
예제 #3
0
        public ApiResponse <UserAccountApiModel> UpdateUserProfile(UserAccountApiModel userProfile)
        {
            var response = new ApiResponse <UserAccountApiModel>();

            var user = _context.Users.FirstOrDefault(x => x.Id == userProfile.Id);

            if (user != null)
            {
                user.Email            = userProfile.Email;
                user.ContactNumber    = userProfile.ContactNumber;
                user.ProfileImagePath = userProfile.ProfileImagePath;

                _context.Entry(user).State = EntityState.Modified;
                int rowAffected = _context.SaveChanges();
                response.IsSucceeded = rowAffected > 0;
            }

            response.DisplayMessage = response.IsSucceeded? "Your profile has successfully updated":"Failed , Please try after some time";
            response.Result         = userProfile;

            return(response);
        }
예제 #4
0
        public ApiResponse <QuizApiModel> CreateQuiz(QuizApiModel quizApiModel)
        {
            var response = new ApiResponse <QuizApiModel>();

            var quiz = quizApiModel.ToQuize();

            quiz.CreatedDate = DateTime.Now;

            _context.Quizes.Add(quiz);
            int rowAffected = _context.SaveChanges();

            response.IsSucceeded = rowAffected > 0;
            quizApiModel.Id      = quiz.Id;
            response.Result      = quizApiModel;

            return(response);
        }