Esempio n. 1
0
        public bool AddQuestion(QuestionBankVM model)
        {
            if (model == null)
            {
                throw new Exception("There is no Entry!");
            }

            var addQuestion = new QuestionBank
            {
                Question       = model.question,
                CreatedBy      = model.createdBy,
                IsDeleted      = model.isDeleted,
                TestCategoryId = model.testCategoryId,
                DateOfDeletion = model.dateOfDeletion,
                DeletedBy      = model.deletedBy,
                OptionA        = model.optionA,
                OptionB        = model.optionB
            };

            var que = _context.QuestionBank.Add(addQuestion);

            if (_context.SaveChanges() > 0)
            {
                _context.QuestionOption.Add(new QuestionOption {
                    QuestionBankId = que.QuestionBankId, QuetionOptionName = model.optionA, OptionLabel = "A"
                });
                _context.QuestionOption.Add(new QuestionOption {
                    QuestionBankId = que.QuestionBankId, QuetionOptionName = model.optionB, OptionLabel = "B"
                });
            }
            return(_context.SaveChanges() > 0);
        }
Esempio n. 2
0
        public bool AddTestSetup(TestSetupVM model)
        {
            if (model == null)
            {
                throw new Exception("There is no Entry!");
            }

            var setUp = new TestSetup()
            {
                DisplayResult = model.DisplayResult,
                EndDate       = model.EndDate,
                StartDate     = model.StartDate,
                StartTime     = model.StartTime,
                StopTime      = model.StopTime
            };

            _context.TestSetup.Add(setUp);

            if (_context.SaveChanges() > 0)
            {
                var testSetupId = setUp.TestSetupId;

                foreach (var id in model.QuestionBankIds)
                {
                    var publishQuestion = new PublishedQuestion
                    {
                        QuestionBankId = id.questionBankId,
                        TestSetupId    = testSetupId
                    };

                    _context.PublishedQuestion.Add(publishQuestion);
                }
            }
            return(_context.SaveChanges() > 0);
        }
Esempio n. 3
0
        public bool AddQuestionOption(QuestionOptionVM model)
        {
            if (model == null)
            {
                throw new Exception("There is no Entry!");
            }

            var qOption = new QuestionOption
            {
                QuetionOptionName = model.quetionOptionName
            };

            _context.QuestionOption.Add(qOption);

            return(_context.SaveChanges() > 0);
        }
        public bool AddCorrectAnswer(CorrectAnswerVM model)
        {
            if (model == null)
            {
                throw new Exception("There is no Entry!");
            }

            var answer = new CorrectAnswer
            {
                QuestionBankId       = model.questionBankId,
                QuestionOptionId     = model.questionOptionId,
                QuestionOptionTypeId = model.questionOptionTypeId,
            };

            _context.CorrectAnswer.Add(answer);

            return(_context.SaveChanges() > 0);
        }
        public bool AddTestCategory(TestCategoryVM model)
        {
            if (model == null)
            {
                throw new Exception("There is no Entry!");
            }
            ;

            var category = new TestCategory
            {
                CategoryName = model.categoryName,
                CreatedBy    = model.createdBy,
                DateCreated  = model.dateCreated,
                IsDelete     = model.isDelete
            };

            _context.TestCategory.Add(category);

            return(_context.SaveChanges() > 0);
        }
        public bool RegisterUser(UserLoginDetailVM user)
        {
            if (UserRegistrationExist(user.userName.ToLower()) == true)
            {
                throw new Exception("Username Exist! Please login.");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(user.password, out passwordHash, out passwordSalt);

            var userRegistration = new LoginActivity
            {
                FirstName           = user.firstName,
                LastName            = user.lastName,
                Email               = user.email,
                UserName            = user.userName,
                Gender              = user.gender,
                PasswordHash        = passwordHash,
                PasswordSalt        = passwordSalt,
                CreationDate        = DateTime.Now,
                IsActive            = true,
                IsLocked            = false,
                IsEmailConfirmed    = true,
                IsLockoutEnabled    = false,
                IsLogout            = false,
                IsFirstLoginAttempt = false,
            };

            _context.LoginActivity.Add(userRegistration);
            if (_context.SaveChanges() > 0)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        public bool UpdateTestResult(TestResultVM model)
        {
            if (model == null)
            {
                throw new Exception("There is no Entry!");
            }

            var result = _context.TestResult.Find(model.testResultId);

            if (result == null)
            {
                throw new Exception("Not found!");
            }

            result.Answer = model.answer;

            return(_context.SaveChanges() > 0);
        }
        public bool deletePublishedQuestion(int PublishedQuestionId)
        {
            if (PublishedQuestionId == 0)
            {
                throw new Exception("There is nothing to delete!");
            }

            var publishQuestion = _context.PublishedQuestion.Find(PublishedQuestionId);

            if (publishQuestion == null)
            {
                throw new Exception("Record not found");
            }

            _context.PublishedQuestion.Remove(publishQuestion);

            return(_context.SaveChanges() > 0);
        }
Esempio n. 9
0
        //public Signup AddProspectiveStudentEntry(SignupVM model)
        //{
        //    if (model == null) throw new Exception("There is no Entry!");

        //    Random generator = new Random();
        //    String token = generator.Next(0, 999999).ToString("D6");

        //    var emailExist = _context.Signup.Any(o => o.Email == model.Email);

        //    if(emailExist == true) throw new Exception("This Email is already register, request for OTP to continue.");

        //    var studentProfile = new Signup
        //    {
        //        FirstName = model.FirstName,
        //        LastName = model.LastName,
        //        MiddleName = model.MiddleName,
        //        MobileNo = model.MobileNo,
        //        Email = model.Email,
        //        DOB = model.DOB,
        //        Program = model.Program,
        //        Address = model.Address,
        //        COR = model.COR,
        //        City = model.City,
        //        Designation = model.Designation,
        //        NOI = model.NOI,
        //        Token = token,
        //        TokenExpirationDate = DateTime.Now,
        //        ExamDate = model.ExamDate

        //    };



        //   var user = _context.Signup.Add(studentProfile);

        //    string messageContent = $"Dear {user.FirstName + " " + user.LastName}, <br /><br />" +
        //                             "Thank you for your interest. <br />" +
        //                             "Kindly enter this token : " + token + " to complete your registration";

        //    if (_context.SaveChanges() > 0)
        //    {
        //        SendEmailAPI.SendEmail("", user.Email, "OTP from Skyline University NIgeria", messageContent, "");
        //        sendSMSAPI.SendSMS(smsUsername, smsPassword, user.MobileNo, messageContent, "SMS");
        //    }
        //    return user;

        //}

        public Signup AddProspectiveStudentEntry(SignupVM model)
        {
            if (model == null)
            {
                throw new Exception("There is no Entry!");
            }

            var username = _context.Signup.Where(x => x.UserName == model.UserName).FirstOrDefault();

            if (username == null)
            {
                Random generator = new Random();
                String token     = generator.Next(0, 999999).ToString("D6");

                string tokenizer = generator.Next(0, 9999).ToString("D4");

                var emailExist = _context.Signup.Any(o => o.Email == model.Email);

                // if (emailExist == true) throw new Exception("This Email is already registered, request for OTP to continue.");
                if (emailExist == true)
                {
                    throw new Exception("This Email is already registered");
                }

                var studentProfile = new Signup
                {
                    FirstName           = model.FirstName,
                    LastName            = model.LastName,
                    MiddleName          = model.MiddleName,
                    MobileNo            = model.MobileNo,
                    Email               = model.Email,
                    DOB                 = model.DOB,
                    Program             = model.Program,
                    Address             = model.Address,
                    COR                 = model.COR,
                    City                = model.City,
                    Designation         = model.Designation,
                    NOI                 = model.NOI,
                    Token               = token,
                    TokenExpirationDate = DateTime.Now,
                    ExamDate            = model.ExamDate,
                    State               = model.State,
                    UserName            = model.UserName == null ? tokenizer : model.UserName,
                    SchoolID            = model.SchoolID,
                    Levels              = model.Levels
                };



                var user = _context.Signup.Add(studentProfile);

                string messageContent = $"Dear {user.FirstName + " " + user.LastName}, <br /><br />" +
                                        "Thank you for your interest. <br />" +
                                        "Kindly enter this token : " + token + " to complete your registration";

                if (_context.SaveChanges() > 0)
                {
                    var mobile = "234" + user.MobileNo;
                    SendEmailAPI.SendEmail("", user.Email, "OTP from Skyline University NIgeria", messageContent, "");

                    var url = "http://ngn.rmlconnect.net:8080/bulksms/bulksms?" + "username="******"&password="******"&source=" + school + "&destination=" + mobile + "&type=" + 0 + "&dlr=" + 1 + "&message=your token is:" + token;

                    var r = client.GetAsync(url).Result;
                    if (r.IsSuccessStatusCode == true)
                    {
                    }
                }

                return(user);
            }
            else
            {
                throw new Exception("You have already taken the test");
            }
        }