public CMSResult Update(OfflineTestPaper OfflineTestPaper)
        {
            CMSResult result = new CMSResult();

            var isExists = _repository.Project <OfflineTestPaper, bool>(ofline => (from b in ofline
                                                                                   where b.OfflineTestPaperId != OfflineTestPaper.OfflineTestPaperId && b.Title == OfflineTestPaper.Title
                                                                                   select b).Any());

            if (isExists)
            {
                result.Results.Add(new Result {
                    IsSuccessful = false, Message = string.Format("Offline Test '{0}' already exists!", OfflineTestPaper.Title)
                });
            }
            else
            {
                var offlineTests = _repository.Load <OfflineTestPaper>(x => x.OfflineTestPaperId == OfflineTestPaper.OfflineTestPaperId);

                offlineTests.Title       = OfflineTestPaper.Title;
                offlineTests.TestDate    = OfflineTestPaper.TestDate;
                offlineTests.TestInTime  = OfflineTestPaper.TestInTime;
                offlineTests.TestOutTime = OfflineTestPaper.TestOutTime;
                offlineTests.TotalMarks  = OfflineTestPaper.TotalMarks;
                _repository.Update(offlineTests);
                result.Results.Add(new Result {
                    IsSuccessful = true, Message = string.Format("Exam schedule '{0}' updated successfully!", offlineTests.Title)
                });
            }
            return(result);
        }
        public CMSResult Save(OfflineTestPaper offlineTestPaper)
        {
            CMSResult result   = new CMSResult();
            var       isExists = _repository.Project <OfflineTestPaper, bool>(OfflineTestPapers => (
                                                                                  from offlineTest in OfflineTestPapers
                                                                                  where offlineTest.Title == offlineTestPaper.Title
                                                                                  select offlineTest)
                                                                              .Any());

            if (isExists)
            {
                result.Results.Add(new Result {
                    IsSuccessful = false, Message = string.Format("Exam schedule '{0}' already exists!", offlineTestPaper.Title)
                });
            }
            else
            {
                _repository.Add(offlineTestPaper);
                _repository.CommitChanges();
                result.Results.Add(new Result {
                    IsSuccessful = true, Message = string.Format("Exam schedule Notification added successfully!")
                });
            }
            return(result);
        }
Exemplo n.º 3
0
        public JsonResult SendOffineTestPaperNotification(OfflineTestPaperViewModel viewModel)
        {
            var           cmsResult            = new CMSResult();
            List <string> listOfEmail          = new List <string>();
            List <string> listOfName           = new List <string>();
            List <string> listOfNumber         = new List <string>();
            var           finalParentPlayerId  = new List <ListOfPlayerId>();
            var           finalStudentPlayerId = new List <ListOfPlayerId>();

            if (ModelState.IsValid)
            {
                TimeSpan span = (Convert.ToDateTime(viewModel.TestOutTime) - Convert.ToDateTime(viewModel.TestInTime));
                if (viewModel.TestInTime != null && viewModel.TestOutTime != null && Convert.ToDateTime(viewModel.TestInTime).ToShortTimeString() != "12:00 AM" && Convert.ToDateTime(viewModel.TestOutTime).ToShortTimeString() != "12:00 AM" && viewModel.TestOutTime != null && !(span >= TimeSpan.FromMinutes(30) && span <= TimeSpan.FromHours(3)))
                {
                    cmsResult.Results.Add(new Result {
                        Message = "The time limit should be min lengh of (1/2 hr) & max length of  (3 hrs).", IsSuccessful = false
                    });
                }
                else
                {
                    string subject = "Exam Schedule Create";
                    try
                    {
                        var studentList = _studentService.GetStudentByBranchClassBatchForTestPaper(viewModel.SelectedBranches, viewModel.ClassId.ToString(), viewModel.SelectedBatches);
                        var batchIds    = viewModel.SelectedBatches.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(int.Parse).ToList();
                        var batch       = _repository.LoadList <Batch>(x => batchIds.Contains(x.BatchId));

                        foreach (var student in studentList)
                        {
                            if (batchIds.Contains(student.BatchId))
                            {
                                if (viewModel.AppNotification)
                                {
                                    if (student.parentAppPlayerId != "" && student.parentAppPlayerId != null)
                                    {
                                        finalParentPlayerId.Add(new ListOfPlayerId
                                        {
                                            SId            = student.SId,
                                            ParentPlayerId = student.parentAppPlayerId
                                        });
                                    }
                                    if (student.studentAppPlayerId != "" && student.studentAppPlayerId != null)
                                    {
                                        finalStudentPlayerId.Add(new ListOfPlayerId
                                        {
                                            SId            = student.SId,
                                            ParentPlayerId = student.studentAppPlayerId
                                        });
                                    }
                                }

                                listOfEmail.Add(student.Email);
                                listOfName.Add(student.Name);
                                listOfNumber.Add(student.StudentContact);
                            }
                        }

                        if (listOfNumber.Count > 0)
                        {
                            var offlineTestPaper = new OfflineTestPaper
                            {
                                OfflineTestPaperId = viewModel.OfflineTestPaperId,
                                Title            = viewModel.Title,
                                TestDate         = viewModel.TestDate,
                                TestInTime       = viewModel.TestInTime == null ? DateTime.Now.Date : Convert.ToDateTime(viewModel.TestInTime.Trim()),
                                TestOutTime      = viewModel.TestOutTime == null ? DateTime.Now.Date : Convert.ToDateTime(viewModel.TestOutTime.Trim()),
                                TotalMarks       = viewModel.TotalMarks,
                                SelectedBranches = viewModel.SelectedBranches,
                                SelectedBatches  = viewModel.SelectedBatches,
                                ClassId          = viewModel.ClassId,
                                SubjectId        = viewModel.SubjectId,
                                Media            = viewModel.Media
                            };
                            var result = _offlineTestPaper.Save(offlineTestPaper);

                            if (result.Success)
                            {
                                var offlineTestPaperId = offlineTestPaper.OfflineTestPaperId;
                                var roleUserId         = User.Identity.GetUserId();
                                var roles = _aspNetRolesService.GetCurrentUserRole(roleUserId);
                                if (roles == "BranchAdmin")
                                {
                                    var resultEmail = sendMailfromBranchAdmin(viewModel.Title, viewModel.Media);
                                }

                                cmsResult = SendNotificationToStudent(viewModel, subject, offlineTestPaperId, listOfEmail, listOfName, listOfNumber,
                                                                      finalParentPlayerId, finalStudentPlayerId);

                                cmsResult.Results.Add(new Result {
                                    Message = result.Results[0].Message, IsSuccessful = true
                                });
                            }
                            else
                            {
                                cmsResult.Results.Add(new Result {
                                    Message = result.Results[0].Message, IsSuccessful = false
                                });
                            }
                        }
                        else
                        {
                            cmsResult.Results.Add(new Result {
                                Message = "No student available please select another batch.", IsSuccessful = false
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex.Message + "catch SendOffineTestPaperNotification");
                        throw;
                    }
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(x => x.Errors).ToArray();
                foreach (var item in errors)
                {
                    cmsResult.Results.Add(new Result {
                        Message = item.ErrorMessage, IsSuccessful = false
                    });
                }
            }

            return(Json(cmsResult, JsonRequestBehavior.AllowGet));
        }