public async Task <IActionResult> Create(ExamModel model)
        {
            ViewData["msg"] = "";
            if (string.IsNullOrEmpty(model.ExamName))
            {
                return(View(model));
            }
            string accessToken = CookieEncoder.DecodeToken(Request.Cookies["access_token_cookie"]);
            var    allExam     = await _examService.Create(
                model,
                Int32.Parse(User.FindFirst("UserID").Value),
                accessToken);

            if (allExam != null && allExam.msg != null)
            {
                ViewData["msg"] = allExam.msg;
                return(View());
            }
            else if (allExam == null)
            {
                ViewData["msg"] = "Error";
                return(View());
            }
            else
            {
                ViewData["msg"] = "Thêm mới thành công";
                return(View());
            }
        }
Пример #2
0
        private void ExamNameTV_Click(object sender, ExamAdapterClickEventArgs e)
        {
            ExamModel examname_clicked = this.ExamList[e.Position];
            string    examname         = examname_clicked.get_exam_name();
            Dialog    nameDialog       = new Dialog(this);

            nameDialog.SetContentView(Resource.Id.dialog_name_update);
            EditText editText = (EditText)nameDialog.FindViewById(Resource.Id.dialog_name_editText);

            editText.Text = examname;
            /* Non riconosce più android.support.design e quindi ho messo il design che sta in google.design*/
            TextInputLayout textInputLayout = (TextInputLayout)nameDialog.FindViewById(Resource.Id.dialog_name_input_layout);

            Android.Widget.Button okButton = (Android.Widget.Button)nameDialog.FindViewById(Resource.Id.name_ok);
            okButton.Click += async delegate
            {
                string examNameNew = editText.Text.ToUpper();
                if (examNameNew.Trim().Equals(""))
                {
                    textInputLayout.SetErrorTextAppearance(Resource.String.empty_name_field);
                    textInputLayout.RequestFocus();
                }
                else if (examNameNew.Length > 15)
                {
                    textInputLayout.SetErrorTextAppearance(Resource.String.overflow_name_field);
                    textInputLayout.RequestFocus();
                }
                else if (IsSameName(examNameNew))
                {
                    textInputLayout.SetErrorTextAppearance(Resource.String.used_name);
                    textInputLayout.RequestFocus();
                }
                else
                { /*
                   *     Google.Cloud.Firestore.CollectionReference exams = database.Collection("exams");
                   *    Google.Cloud.Firestore.DocumentReference examDoc = exams.Document(examname);
                   *    Google.Cloud.Firestore.DocumentSnapshot snapshot = await examDoc.GetSnapshotAsync();
                   *    if (snapshot.Exists)
                   *    {
                   *        await exams.Document(examNameNew).SetAsync(snapshot);
                   *        await examDoc.DeleteAsync();
                   *    }
                   */
                }


                bool IsSameName(string examNewName)
                {
                    for (int j = 0; j < adapter.ItemCount; j++)
                    {
                        if (ExamList[j].examName.Equals(examNewName))
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
            };
        }
    }
Пример #3
0
        public ResponseModel <List <ExamModel> > ListExams()
        {
            ResponseModel <List <ExamModel> > result = new ResponseModel <List <ExamModel> > {
                Data = new List <ExamModel>()
            };

            try
            {
                var lst = _context.Exams.Include("ExamQuestions").Where(k => k.IsActive == true || k.IsActive == null).Select(e => e).ToList();
                foreach (var item in lst)
                {
                    ExamModel model = new ExamModel();
                    model.TestId               = item.TestId;
                    model.TestTitle            = item.TestTitle;
                    model.CreatedOn            = item.CreatedOn;
                    model.IsActive             = item.IsActive;
                    model.IsAttachmentRequired = Convert.ToBoolean(item.IsAttachmentRequired);
                    model.Questions            = item.ExamQuestions.Where(k => k.IsActive == true).Select(a => new QuestionsList {
                        Id = a.QuestionId, Name = a.Question
                    }).ToList();
                    result.Data.Add(model);
                }
                result.status  = true;
                result.message = "success";
            }
            catch (Exception ex)
            {
                result.message = ex.Message;
            }
            return(result);
        }
Пример #4
0
        private static void LoadMockData()
        {
            ExamModel examMock = new ExamModel();

            examMock.Id              = 1;//set
            examMock.TeachrId        = 10;
            examMock.Title           = "JS";
            examMock.DateStarted     = DateTime.Now.AddDays(5);
            examMock.DurationMinutes = 30;
            examMock.Questions.Add(
                new QuestionModel()
            {
                Id           = 1,
                QuestionText = "1 + 1 =",
                Answer       = "2",
                Choices      = new List <string> {
                    "1", "3", "5", "2", "7"
                },
                Points = 10
            }
                );

            examMock.Questions.Add(
                new QuestionModel()
            {
                Id           = 2,
                QuestionText = "1 + _ = 4",
                Answer       = "3",
                Choices      = new List <string> {
                    "1", "5", "3", "7", "10"
                },
                Points = 10
            }
                );

            _allExams.Add(examMock);


            ExamModel examMock2 = new ExamModel();

            examMock2.Id              = 2;//set
            examMock2.TeachrId        = 20;
            examMock2.Title           = "c#";
            examMock2.DateStarted     = DateTime.Now.AddDays(2);
            examMock2.DurationMinutes = 60;
            examMock2.Questions.Add(
                new QuestionModel()
            {
                Id           = 1,
                QuestionText = "WHAT IS REPOSITORY?",
                Answer       = "2",
                Choices      = new List <string> {
                    "DB ACCESS Pattern", "SPECIAL PROPERTY", "List Of Objects", "Methos in String Object"
                },
                Points = 10
            }
                );

            _allExams.Add(examMock2);
        }
Пример #5
0
        public void Exams_Controller_Test_On_EditModel_With_Invalid_Model()
        {
            //Arrange
            Guid     id           = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            string   title        = "TestT";
            string   observations = "TestF";
            DateTime dateStart    = DateTime.Now;
            DateTime dateEnd      = DateTime.Now.AddDays(1);

            Exam expectedExams = new Exam(title, observations, dateStart, dateEnd);

            expectedExams.Id = id;

            ExamModel expectedModel = new ExamModel();

            expectedModel.Title = " ";

            var repo = Substitute.For <IRepository>();
            var sut  = new ExamsController(repo);

            repo.Update(expectedExams);

            //Act
            sut.ModelState.AddModelError("FirstName", "Firstname Required");
            var actual = sut.Edit(id, expectedExams).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
        }
Пример #6
0
        public ActionResult InsertQuestion(ExamModel loExam)
        {
            ExamDataContext loExamContext = new ExamDataContext();

            TempData["msg"] = loExamContext.InsertQuestion(loExam);
            return(RedirectToAction("GenerateExam"));
        }
Пример #7
0
 public TestScore(ExamModel e)
 {
     Type      = TestType.Exam;
     Date      = e.examDate;
     Score     = e.examScore;
     SubjectId = e.SubjectId;
 }
Пример #8
0
        public IActionResult SaveExam(ExamModel examModel)
        {
            if (!ModelState.IsValid)
            {
                return(Content(UiMessages.WrongMessage));
            }

            ExamMapper examMapper = new ExamMapper();
            Exam1      exam       = examMapper.Map(examModel);

            exam.Creator = CurrentUser;

            if (exam.ID != 0)
            {
                DB.ExamRepository.Update(exam);
                TempData["Message"] = UiMessages.SuccesMessage;
            }
            else
            {
                DB.ExamRepository.Add(exam);
                TempData["Message"] = UiMessages.SuccesMessage;
            }

            return(RedirectToAction("Index"));
        }
Пример #9
0
        private async void DeleteExamBtn_Click(object sender, RoutedEventArgs e)
        {
            IParentWindow parent;

            if (MyAdmin != null)
            {
                parent = ParentFinder.FindParent <AdminPanelWindow>(this);
            }
            else
            {
                parent = ParentFinder.FindParent <TeacherPanelWindow>(this);
            }

            MessageDialogResult r = await parent.ShowMessage("Warning",
                                                             "Are you sure you want to delete this exam",
                                                             MessageDialogStyle.AffirmativeAndNegative);

            if (r == MessageDialogResult.Negative)
            {
                return;
            }
            ExamModel model = (ExamModel)examsGrid.SelectedItem;

            GlobalConfig.Connection.DeleteExam_ById(model.Id);
            MyExams.Remove(model);
            WireUpLists(MyExams);
        }
        public ActionResult AddExam(ExamViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var currentUser   = AccountServiceCaller.Get(User.Identity.Name);
            var userOrganizer = OrganizerServiceCaller.Get(currentUser.OrganizerId);
            var newExam       = new ExamModel();

            newExam.OrganizerId = userOrganizer.Id;
            newExam.CourseName  = model.CourseName;
            newExam.Hour        = model.Hour;
            newExam.Date        = model.ExamDay;
            newExam.Room        = model.ExamRoom;
            newExam.Difficulty  = model.Difficulty;

            try
            {
                ExamServiceCaller.Add(newExam);
                return(RedirectToAction("Index", "Exam"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
Пример #11
0
        public HttpResponseMessage PostExam([FromBody] ExamModel model)
        {
            var nullData = model == null;

            if (nullData)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new { Message = "Invalid data" }));
            }
            if (_userDal.GetUserById(model.UserId) == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new { Message = "User not found" }));
            }
            if (_testDal.GetTestById(model.TestId) == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new { Message = "Test not found" }));
            }
            var userExam = _examDal.GetExamByUserId(model.UserId);

            if (userExam != null && String.IsNullOrEmpty(userExam.Grade))
            {
                _examDal.UpdateUserTest(model.UserId, model.TestId);
                return(Request.CreateResponse(HttpStatusCode.Created, new { Message = "User was assigned test" }));
            }


            _examDal.AssignTestToUser(model.UserId, model.TestId);

            return(Request.CreateResponse(HttpStatusCode.Created, new { Message = "User was assigned test" }));
        }
Пример #12
0
        public ExamModel GetExamById(int Id)
        {
            ExamModel examModel = null;

            using (var connection = new SqlConnection(this.ConnectionString))
            {
                connection.Open();
                //Command (SQL QUEERY)
                SqlCommand allCommand = new SqlCommand("SELECT * FROM Exams WHERE Id =" + Id, connection);
                // READ ROW BY ROW READER
                using (var reader = allCommand.ExecuteReader())
                {
                    //Read ROW BY ROW
                    while (reader.Read())
                    {
                        examModel                 = new ExamModel();
                        examModel.Id              = reader.GetInt32(0);
                        examModel.Title           = reader.GetString(1);
                        examModel.TeachrId        = reader.GetInt32(2);
                        examModel.DurationMinutes = reader.GetInt32(3);
                        examModel.DateStarted     = reader.GetDateTime(4);
                    }
                }
            }

            return(examModel);
        }
Пример #13
0
        public List <ExamModel> GetAllExams()
        {
            List <ExamModel> examsList = new List <ExamModel>();

            using (var connection = new SqlConnection(this.ConnectionString))
            {
                connection.Open();
                //Command (SQL QUEERY)
                SqlCommand allCommand = new SqlCommand("SELECT * FROM Exams", connection);
                // READ ROW BY ROW READER
                using (var reader = allCommand.ExecuteReader())
                {
                    //Read ROW BY ROW
                    while (reader.Read())
                    {
                        ExamModel examModel = new ExamModel();
                        examModel.Id              = reader.GetInt32(0);
                        examModel.Title           = reader.GetString(1);
                        examModel.DateStarted     = reader.GetDateTime(2);
                        examModel.DurationMinutes = reader.GetInt32(3);
                        examModel.TeachrId        = reader.GetInt32(4);
                        examsList.Add(examModel);
                    }
                }
            }
            return(examsList);
        }
        public async Task <IActionResult> Edit(int id)
        {
            ViewData["msg"] = "";
            try
            {
                string accessToken = CookieEncoder.DecodeToken(Request.Cookies["access_token_cookie"]);
                var    res         = await _examService.GetByID(id, accessToken);

                if (res.data == null || res.msg != null)
                {
                    ViewData["msg"] = res.msg;
                }
                var exam  = res.data;
                var model = new ExamModel()
                {
                    ID         = exam.ID,
                    ExamName   = exam.ExamName,
                    ImageURL   = exam.ImageURL,
                    CategoryID = exam.CategoryID,
                    isActive   = exam.isActive,
                    isPrivate  = exam.isPrivate,
                    Time       = exam.Time
                };
                return(View(model));
            }
            catch (Exception)
            {
                ViewData["msg"] = "Lỗi hệ thống. Thử lại sau.";
                return(View());
            }
        }
        public ActionResult getExamDetail(int eid)
        {
            int uid = 0;
            int did = 0;
            int rid = 0;

            if (Session["UserId"] != null)
            {
                uid = Convert.ToInt32(Session["UserId"].ToString());
                did = Convert.ToInt32(Session["DID"].ToString());
                rid = Convert.ToInt32(Session["RoleID"].ToString());
            }
            ExamModel objModel   = new ExamModel();
            QRService objService = new QRService();

            objModel = objService.getByID(eid);

            List <ExamTranModel> lstShedule = new List <ExamTranModel>();

            lstShedule            = objService.getExamShedule(eid);
            objModel.ListSchedule = new List <ExamTranModel>();
            objModel.ListSchedule.AddRange(lstShedule);
            //return Json(objModel, JsonRequestBehavior.AllowGet);
            return(PartialView("_ExamDetail", objModel));
        }
Пример #16
0
        private async void FileLink_Click(object sender, RoutedEventArgs e)
        {
            ExamModel model = (ExamModel)examsGrid.SelectedItem;

            try
            {
                System.Diagnostics.Process.Start(model.FilePath);
            }
            catch (Exception)
            {
                IParentWindow parent;
                if (MyAdmin != null)
                {
                    parent = ParentFinder.FindParent <AdminPanelWindow>(this);
                }
                else
                {
                    parent = ParentFinder.FindParent <TeacherPanelWindow>(this);
                }
                MessageDialogResult r = await parent.ShowMessage("File Not Found",
                                                                 "The requested excel file wasn't found. Do you want to create a new file?",
                                                                 MessageDialogStyle.AffirmativeAndNegative);

                if (r == MessageDialogResult.Affirmative)
                {
                    CreateExcelFile();
                }
            }
        }
Пример #17
0
        // [ValidateInput(false)]
        public ActionResult Create(ExamModel examModel)
        {
            examModel.LastUpdatedBy = User.Identity.Name;
            examModel.LastUpdatedOn = DateTime.Now;
            ResponseModel <ExamModel> result = null;

            if (examModel.TestId == 0)
            {
                result = _exam.Save(examModel);
                if (result.Data.TestId > 0)
                {
                    _examQuestion.Save(examModel.Questions, result.Data.TestId);
                }
            }
            else
            {
                result = _exam.Update(examModel);
                _examQuestion.Update(examModel.Questions, examModel.TestId);
            }
            if (result.status)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.ErrorMessage = result.message;
                return(View("Error"));
            }
        }
Пример #18
0
        public ExamModel GetExam(int StudentId, int ModuleId)
        {
            var           Exam       = new ExamModel();
            SqlConnection connection = new SqlConnection(ConnectoionString);

            try
            {
                connection.Open();
                string        Query   = "SELECT * FROM Exams WHERE StudentId =" + StudentId + " AND ModuleId=" + ModuleId + "";
                SqlCommand    command = new SqlCommand(Query, connection);
                SqlDataReader reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    Exam = new ExamModel()
                    {
                        ExamId    = Int32.Parse(reader["ExamId"].ToString()),
                        StudentId = Int32.Parse(reader["StudentId"].ToString()),
                        ModuleId  = Int32.Parse(reader["ModuleId"].ToString()),
                        Attempts  = Int32.Parse(reader["Attempts"].ToString()),
                        Marks     = Int32.Parse(reader["Marks"].ToString())
                    };
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                connection.Close();
            }

            return(Exam);
        }
Пример #19
0
        public ExamModel GetExamByIdForCheckingOperation(int examId)
        {
            var examDatas = _examRepo.GetAll().Where(x => x.Id == examId).FirstOrDefault();

            var examModel = new ExamModel();

            examModel.WiredTypingTitle   = examDatas.WiredTypingTitle;
            examModel.WiredTypingContent = examDatas.WiredTypingContent;

            for (int i = 0; i < examDatas.Questions.Count; i++)
            {
                examModel.Questions.Add(new QuestionModel
                {
                    QuestionId    = examDatas.Questions[i].Id,
                    QuestionText  = examDatas.Questions[i].QuestionText,
                    Choice_A      = examDatas.Questions[i].Choice_A,
                    Choice_B      = examDatas.Questions[i].Choice_B,
                    Choice_C      = examDatas.Questions[i].Choice_C,
                    Choice_D      = examDatas.Questions[i].Choice_D,
                    CorrectChoice = examDatas.Questions[i].CorrectChoice
                });
            }

            examModel.UserId     = examDatas.UserId;
            examModel.CreateDate = examDatas.CreateDate;

            return(examModel);
        }
Пример #20
0
        public ActionResult Result(ExamModel model)
        {
            ExamService objService = new ExamService();
            int         uid        = 0;

            if (Session["UID"] != null)
            {
                uid = Convert.ToInt32(Session["UID"].ToString());
            }
            var lstResult = Dbcontext.ResultMasters.Where(m => m.EID == model.EID && m.StudID == model.StudID && m.SubID == model.SubID).SingleOrDefault();

            if (lstResult != null)
            {
                ResultMaster res = Dbcontext.ResultMasters.Where(r => r.EID == model.EID && r.StudID == model.StudID && r.SubID == model.SubID).SingleOrDefault();
                res.Marks       = model.Marks;
                res.UpdatedBy   = uid;
                res.UpdatedDate = System.DateTime.Now;
                Dbcontext.SaveChanges();
            }
            else
            {
                model.CreatedBy   = uid;
                model.CreatedDate = System.DateTime.Now;
                objService.InsertResult(model);
            }
            return(RedirectToAction("Result"));
        }
Пример #21
0
        public JsonResult ExamEdit(int ExamId, ExamModel ExamModel)
        {
            try
            {
                if (ExamId == 0)
                {
                    Core3Base.Infra.Data.Entity.Exam Exam = new Core3Base.Infra.Data.Entity.Exam
                    {
                        ExamName = ExamModel.Exam.ExamName,
                        IsActive = ExamModel.Exam.IsActive,
                    };

                    return(Json(_ExamService.Add(Exam).HttpGetResponse()));
                }
                else
                {
                    var Exam = _ExamService.GetExamById(ExamId).Result;
                    Exam.ExamName     = ExamModel.Exam.ExamName;
                    Exam.IsActive     = ExamModel.Exam.IsActive;
                    Exam.DateModified = DateTime.Now;

                    return(Json(_ExamService.Update(Exam).HttpGetResponse()));
                }
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }
        }
Пример #22
0
        public ActionResult Schedule(int id)
        {
            List <ExamModel> lstStud    = new List <ExamModel>();
            ExamModel        objModel   = new ExamModel();
            ExamService      objService = new ExamService();

            var lstExam = Dbcontext.ExamMasters.Where(m => m.EID == id).SingleOrDefault();

            int?stdID     = lstExam.StdID;
            int?schoolID  = lstExam.SchoolID;
            int eid       = lstExam.EID;
            var lstSchool = Dbcontext.SchoolMasters.Where(m => m.SchoolID == schoolID).SingleOrDefault();
            var lstStd    = Dbcontext.StandardMasters.Where(m => m.StdID == stdID).SingleOrDefault();
            List <SubjectModel> lstSub = new List <SubjectModel>();
            var lstSchedule            = Dbcontext.ExamTrans.Where(m => m.EID == eid && m.SchoolID == schoolID && m.StdID == stdID).ToList();

            if (lstSchedule.Count > 0)
            {
                lstSub           = objService.getShedule(id, schoolID, stdID);
                objModel.ListSub = new List <SubjectModel>();
                objModel.ListSub.AddRange(lstSub);
            }
            else
            {
                lstSub           = objService.getSubByStdID(stdID);
                objModel.ListSub = new List <SubjectModel>();
                objModel.ListSub.AddRange(lstSub);
            }

            objModel.ExamDetails      = lstExam;
            objModel.StdDetail        = lstStd;
            objModel.SchoolMastDetail = lstSchool;
            return(View(objModel));
        }
Пример #23
0
        public void Exams_Controller_Test_On_CreateModel_With_Valid_Model()
        {
            //Arrange
            Guid     id           = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            string   title        = "TestT";
            string   observations = "TestF";
            DateTime dateStart    = DateTime.Now;
            DateTime dateEnd      = DateTime.Now.AddDays(1);

            Exam expectedExams = new Exam(title, observations, dateStart, dateEnd);

            expectedExams.Id = id;

            ExamModel expectedModel = new ExamModel();

            var repo = Substitute.For <IRepository>();
            var sut  = new ExamsController(repo);

            repo.Create(expectedExams);

            //Act
            var actual = sut.Create(expectedModel).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(RedirectToActionResult));
        }
Пример #24
0
        public async Task <Exam> Create(ExamModel request, int userID)
        {
            var owner = _db.Users.Where(u => u.Id == userID).FirstOrDefault();

            if (owner == null || owner.isActive == false)
            {
                return(null);
            }
            var category = _db.Categories.Where(c => c.ID == request.CategoryID).FirstOrDefault();
            var exam     = new Exam()
            {
                ExamName     = request.ExamName,
                isPrivate    = request.isPrivate,
                Time         = request.Time * 60,
                ImageURL     = request.ImageURL,
                TimeCreated  = DateTime.Now,
                NumOfAttemps = 0,
                CategoryID   = request.CategoryID,
                Category     = _db.Categories.Where(c => c.ID == request.CategoryID).FirstOrDefault(),
                OwnerID      = userID,
                Owner        = _db.Users.Where(u => u.Id == userID).FirstOrDefault(),
                Questions    = null,
                isActive     = true
            };

            _db.Exams.Add(exam);
            await _db.SaveChangesAsync();

            return(exam);
        }
Пример #25
0
        public void Exams_Controller_Test_On_EditModel_With_Invalid_Id()
        {
            //Arrange
            Guid     id           = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            string   title        = "TestT";
            string   observations = "TestF";
            DateTime dateStart    = DateTime.Now;
            DateTime dateEnd      = DateTime.Now.AddDays(1);

            Exam expectedExams = new Exam(title, observations, dateStart, dateEnd);

            expectedExams.Id = id;

            Guid faultId = new Guid("1e4966f0-68f7-4f24-9f4f-53d528787be5");

            ExamModel expectedModel = new ExamModel();

            expectedModel.Title = " ";

            var repo = Substitute.For <IRepository>();
            var sut  = new ExamsController(repo);

            repo.Update(expectedExams);

            //Act
            var actual = sut.Edit(faultId, expectedExams).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(NotFoundResult));
        }
Пример #26
0
        public IActionResult AddExamModelMultiple(long id, [FromForm] ExamModel examModel)
        {
            string user;
            string Uid;


            Request.Cookies.TryGetValue("User", out user);
            Request.Cookies.TryGetValue("Uid", out Uid);
            var u = _UserService.InspectGuid(new TGuid {
                User = user, Uid = Uid,
            });

            if (!ModelState.IsValid || u == null)
            {
                ModelState.AddModelError(string.Empty, "类型添加错误");
                return(View(examModel));
            }
            var str = Request.Form["AA"] + Request.Form["AB"] + Request.Form["AC"] + Request.Form["AD"];

            examModel.Answer   = str;
            examModel.User     = u.UserName;
            examModel.QClassId = id;
            examModel.Multiple = true;

            _ExamService.AddExamModel(examModel);

            return(RedirectToAction(nameof(Index)));
        }
Пример #27
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment

            View view = inflater.Inflate(Resource.Layout.addexam, container, false);

            addexamnameText = (TextInputLayout)view.FindViewById(Resource.Id.addexamnameText);
            addexamdateText = (TextInputLayout)view.FindViewById(Resource.Id.addexamdateText);
            submitButton    = (Button)view.FindViewById(Resource.Id.submitButton);

            submitButton.Click += async(sender, e) =>
            {
                ExamModel model = new ExamModel();
                model.examName = addexamnameText.EditText.Text;
                model.date     = (Firebase.Timestamp)addexamdateText.EditText.Text;
                await CrossCloudFirestore.Current
                .Instance
                .Collection("exams")
                .Document(addexamnameText.EditText.Text)
                .SetAsync(model);

                this.Dismiss();
            };
            return(view);
        }
        public ActionResult showExam(short id)
        {
            if (Session["username"] != null && Session["role"].Equals("student"))
            {
                var studentId = (short)Session["id"];
                var examTest  = _context.exam_gradeDb.Where(e => e.student_id == studentId && e.course_id == id).FirstOrDefault();

                if (examTest == null)
                {
                    var         questions = _context.questionDb.Where(q => q.CourseId == id).ToList();
                    CourseModel course    = _context.courseDb.Single(c => c.id == id);

                    var viewModel = new CourseQuestionsViewModel
                    {
                        course    = course,
                        questions = questions
                    };

                    ExamModel exam = new ExamModel();
                    exam.course_id  = id;
                    exam.student_id = (short)Session["id"];
                    exam.grade      = 0;
                    _context.exam_gradeDb.Add(exam);
                    _context.SaveChanges();
                    return(View(viewModel));
                }
                else
                {
                    return(RedirectToAction("showGrade", new RouteValueDictionary(new { Controller = "Student", Action = "showGrade", id = id })));
                }
            }

            return(RedirectToAction("Login", "Home"));
        }
Пример #29
0
        public ResponseModel <ExamModel> Save(ExamModel model)
        {
            ResponseModel <ExamModel> result = new ResponseModel <ExamModel> {
                Data = new ExamModel()
            };

            try
            {
                Exams db = new Exams();
                db.TestTitle            = model.TestTitle;
                db.CreatedOn            = DateTime.Now;
                db.IsAttachmentRequired = model.IsAttachmentRequired;
                db.IsActive             = true;
                db.LastUpdatedBy        = model.LastUpdatedBy;
                db.LastUpdatedOn        = model.LastUpdatedOn;
                _context.Exams.Add(db);
                _context.SaveChanges();
                result = new ResponseModel <ExamModel> {
                    status = true, message = "Success", Data = new ExamModel()
                    {
                        TestId = db.TestId, TestTitle = db.TestTitle
                    }
                };
            }
            catch (Exception ex)
            {
                result.status  = false;
                result.message = ex.Message;
                result.Data    = new ExamModel()
                {
                    TestId = 0, TestTitle = null
                };
            }
            return(result);
        }
        public async Task <IActionResult> Edit(int id, ExamModel model)
        {
            ViewData["msg"] = "";
            try
            {
                if (id != model.ID)
                {
                    ViewData["msg"] = "Không hợp lệ";
                    return(View(model));
                }
                if (string.IsNullOrEmpty(model.ExamName))
                {
                    ViewData["msg"] = "Không được bỏ trống";
                    return(View(model));
                }
                var token   = CookieEncoder.DecodeToken(Request.Cookies["access_token_cookie"]);
                var newExam = await _examService.Update(id, model, token);

                if (newExam.msg != null)
                {
                    ViewData["msg"] = newExam.msg;
                    return(View());
                }
                ViewData["msg"] = "Cập nhật thành công";
                return(View());
            }
            catch (Exception)
            {
                ViewData["msg"] = "Lỗi hệ thống. Thử lại sau.";
                return(View());
            }
        }