public CMSResult SendNotification(int classId, string title, string filename, string pdfCategory, int pdfuploadId) { var getStudentAppPlayerList = _studentService.GetStudentsAppPlayerIdByClass(classId); var sortlist = getStudentAppPlayerList.Where(x => !string.IsNullOrEmpty(x.studentAppPlayerId)) .Select(y => y.studentAppPlayerId).ToList(); if (sortlist.Count > 0) { var result = _sendNotificationService.SendNotificationByPlayersId(new SendNotification { Message = "PDF-" + title + "$^$ File - " + filename + "$^$ Category - " + pdfCategory + "$^$" + pdfuploadId, PlayerIds = sortlist, AppIds = ConfigurationManager.AppSettings[Common.Constants.StudentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.StudentRestAppId] }); return(result); } else { var result = new CMSResult(); result.Results.Add(new Result { IsSuccessful = false, Message = "There is no student register." }); return(result); } }
public ActionResult Create(InstallmentViewModel viewModel) { ViewBag.ClassId = viewModel.ClassId; ViewBag.BranchId = viewModel.BranchId; ViewBag.UserId = viewModel.UserId; ViewBag.installmentCount = viewModel.InstallmentNo; var students = _studentService.GetStudentById(viewModel.UserId); //var commaseperatedList = students.SelectedSubjects ?? string.Empty; //var subjectIds = commaseperatedList.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(int.Parse); //var subjects = _repository.LoadList<Subject>(x => subjectIds.Contains(x.SubjectId)).ToList(); //string subject = ""; //foreach (var s in subjects) //{ // subject += string.Format("{0}", s.Name); //} //var selectedSubjects =students.BatchName +" - "+ string.Join(",", subject.TrimEnd(',')) ; var studentFinalFee = _studentService.GetStudentFeeByUserId(viewModel.UserId); var paidFee = _installmentService.GetCountInstallment(viewModel.UserId); var remainFee = studentFinalFee - paidFee; var roles = viewModel.CurrentUserRole; var branchId = viewModel.BranchId; var branchName = viewModel.BranchName; var remainingPayment = remainFee - viewModel.Payment; var ReceivedFee = paidFee + viewModel.Payment; viewModel.RemainingFee = remainingPayment; viewModel.TotalFee = (studentFinalFee).ToString(); List <string> listOfPlayerId = new List <string>(); if (ModelState.IsValid) { if (remainFee < viewModel.Payment && remainFee != 0) { ViewBag.StudentName = viewModel.StudentName; ViewBag.TotalFee = viewModel.TotalFee; ViewBag.RemainingFee = viewModel.RemainingFee; _logger.Warn("Payment amount is exceded!"); Warning("Payment amount is exceded!", true); } else if (remainFee == 0) { ViewBag.StudentName = viewModel.StudentName; ViewBag.TotalFee = viewModel.TotalFee; ViewBag.RemainingFee = viewModel.RemainingFee; _logger.Warn("Your Remaining Fee is Nill!"); Warning("Your Remaining Fee is Nill!", true); } else { var result = _installmentService.Save(new Installment { ClassId = viewModel.ClassId, UserId = viewModel.UserId, Payment = viewModel.Payment, RemainingFee = remainingPayment, ReceiptBookNumber = viewModel.ReceiptBookNumber, ReceiptNumber = viewModel.ReceiptNumber, ReceivedFee = ReceivedFee, }); if (result.Success) { ViewBag.ClassId = 0; ViewBag.BranchId = 0; string createdBranchName = "", userName = ""; bool isBranchAdmin = false; if (viewModel.CurrentUserRole == "BranchAdmin") { isBranchAdmin = true; createdBranchName = viewModel.BranchName; userName = User.Identity.GetUserName(); } else { createdBranchName = viewModel.BranchName; userName = User.Identity.GetUserName() + "(" + "Master Admin" + ")"; } string body = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/MailDesign/InstallmentMailDesign.html"))) { body = reader.ReadToEnd(); } body = body.Replace("{BatchWithSubjectName}", viewModel.StudBatch); body = body.Replace("{BranchName}", createdBranchName); body = body.Replace("{StudentName}", viewModel.StudentName); body = body.Replace("{ClassName}", students.ClassName); body = body.Replace("{TotalFees}", studentFinalFee.ToString()); body = body.Replace("{PaidFees}", viewModel.Payment.ToString()); body = body.Replace("{RemainingFees}", remainingPayment.ToString()); body = body.Replace("{UserName}", userName); var emailMessage = new MailModel { Body = body, Subject = "Fees Payment", To = viewModel.Email, IsBranchAdmin = isBranchAdmin }; _emailService.Send(emailMessage); if (viewModel.SMS == true) { string classname; string query = "SELECT name FROM Configuration"; SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(query, con); cmd.Connection = con; con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); classname = dr["name"].ToString(); var smsModel = new SmsModel { Message = "Hi " + classname + "\r\n Student Name: " + viewModel.StudentName + "\r\nPayment: " + viewModel.Payment + "\r\nRemaining Fees: " + viewModel.RemainingFee + "\r\nFees paid successfully.", SendTo = viewModel.ParentContact + "," + viewModel.StudentContact }; var smsResult = _smsService.SendMessage(smsModel); } if (viewModel.AppNotification == true) { listOfPlayerId.Add(viewModel.ParentAppPlayerId); listOfPlayerId = listOfPlayerId.Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); var sendAppNotification = new SendNotification { Message = "Fee-Student Name: " + viewModel.StudentName + " Payment: " + viewModel.Payment + " Remaining Fees: " + viewModel.RemainingFee + " Fees paid successfully.", PlayerIds = listOfPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.ParentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId] }; if (listOfPlayerId.Count > 0) { var sendNotificationResult = _sendNotificationService.SendNotificationByPlayersId(sendAppNotification); } } Success(result.Results.FirstOrDefault().Message); ModelState.Clear(); viewModel = new InstallmentViewModel(); ViewBag.StudentName = ""; ViewBag.TotalFee = "0"; ViewBag.RemainingFee = "0"; ViewBag.installmentCount = ""; } else { _logger.Warn(result.Results.FirstOrDefault().Message); Warning(result.Results.FirstOrDefault().Message, true); ViewBag.StudentName = viewModel.StudentName; ViewBag.TotalFee = viewModel.TotalFee; ViewBag.RemainingFee = viewModel.RemainingFee; } } } else { ViewBag.StudentName = viewModel.StudentName; ViewBag.TotalFee = viewModel.TotalFee; ViewBag.RemainingFee = viewModel.RemainingFee; } if (roles == "Admin") { var branchList = _branchService.GetAllBranches().ToList(); viewModel.Branches = new SelectList(branchList, "BranchId", "Name"); } else if (roles == "BranchAdmin") { } viewModel.CurrentUserRole = roles; var classes = _classService.GetClasses().ToList(); viewModel.Classes = new SelectList(classes, "ClassId", "Name"); return(View(viewModel)); }