public ActionResult Detail(string id) { UnitOfWork uow = new UnitOfWork(); ClassEditModel model = uow.TeacherRepository.GetClassData(id); using (var client = new HttpClient()) { var response = client.PostAsync("https://api.braincert.com/v2/getclassreport?apikey=EBqafLB3sAk1HeCDxr4Z&format=json&classId=" + model.BrainCertId + "", null).Result; response.EnsureSuccessStatusCode(); string responseBody = response.Content.ReadAsStringAsync().Result; if (!responseBody.Contains("error")) { List <AttendanceReport> myProduct = JsonConvert.DeserializeObject <List <AttendanceReport> >(responseBody); List <AttendanceReport> students = myProduct.Where(a => a.isTeacher == 0).ToList(); List <AttendenceReportModel> listRep = new List <AttendenceReportModel>(); for (int i = 0; i < students.Count; i++) { AttendenceReportModel attenReport = uow.TeacherRepository.GetUserInfo(students[i].userId, id); if (attenReport != null) { decimal dec = Convert.ToDecimal(TimeSpan.Parse(students[i].duration).TotalHours); attenReport.CreditsConsumed = String.Format("{0:0.00}", dec); attenReport.CreditsRefund = String.Format("{0:0.00}", attenReport.CreditsUsed - dec); listRep.Add(attenReport); } } ViewBag.Attendence = listRep; } else { return(RedirectToAction("classes", "tutor")); } } return(View(model)); }
public ActionResult ProcessClass(string id) { UnitOfWork uow = new UnitOfWork(); Class classDetail = uow.Classes.Get(x => x.ClassID == id).FirstOrDefault(); if (classDetail != null && classDetail.Status != (int)ClassStatus.Completed) { using (var client = new HttpClient()) { var response = client.PostAsync("https://api.braincert.com/v2/getclassreport?apikey=EBqafLB3sAk1HeCDxr4Z&format=json&classId=" + classDetail.BrainCertId + "", null).Result; response.EnsureSuccessStatusCode(); string responseBody = response.Content.ReadAsStringAsync().Result; List <AttendanceReport> report = JsonConvert.DeserializeObject <List <AttendanceReport> >(responseBody); AttendanceReport studentReport = report.Where(a => a.isTeacher == 0).ToList().FirstOrDefault(); User student = uow.Users.Get(x => x.AutoID == studentReport.userId).FirstOrDefault(); string studentId = student.UserID; AttendenceReportModel attenReport = uow.TeacherRepository.GetUserInfo(studentReport.userId, id); if (attenReport != null) { decimal classTime = Convert.ToDecimal(TimeSpan.Parse(studentReport.duration).TotalHours); attenReport.CreditsConsumed = String.Format("{0:0.00}", classTime); attenReport.CreditsRefund = String.Format("{0:0.00}", attenReport.CreditsUsed - classTime); attenReport.CreditsConsumedInt = classTime; attenReport.CreditsRefundInt = attenReport.CreditsUsed - classTime; attenReport.StudentClassId = studentReport.userId; //mark class as completed classDetail.Status = (int)ClassStatus.Completed; StudentCreditLog creditLog = new StudentCreditLog { ClassID = classDetail.ClassID, UserID = id, CreationDate = DateTime.Now, CreditsUsed = Math.Round(attenReport.CreditsRefundInt, 2), LogType = "Refund" }; uow.StudentCreditLogs.Insert(creditLog); StudentCredit credit = uow.StudentCredits.Get(a => a.StudentID == studentId).FirstOrDefault(); if (credit != null) { credit.LastUpdates = DateTime.Now; credit.TotalCredits = credit.TotalCredits + attenReport.CreditsRefundInt; credit.UsedCredits = credit.UsedCredits - attenReport.CreditsRefundInt; } UpdateTutorWallet(classDetail.TeacherID, classDetail.ClassID, classTime); //payment refund notification Common.AddNotification("Your wallet has beend refunded with " + creditLog.CreditsUsed, "", Session["UserId"].ToString(), studentId, "/student/wallet", (int)NotificationType.Refund); } uow.Save(); } } return(RedirectToAction("classes", "tutor")); }
public ActionResult ProcessAttendence(string id) { UnitOfWork uow = new UnitOfWork(); Class classModel = uow.Classes.Get(x => x.ClassID == id).FirstOrDefault(); if (classModel != null && classModel.Status != (int)ClassStatus.Completed) { using (var client = new HttpClient()) { var response = client.PostAsync("https://api.braincert.com/v2/getclassreport?apikey=EBqafLB3sAk1HeCDxr4Z&format=json&classId=" + classModel.BrainCertId + "", null).Result; response.EnsureSuccessStatusCode(); string responseBody = response.Content.ReadAsStringAsync().Result; List <AttendanceReport> myProduct = JsonConvert.DeserializeObject <List <AttendanceReport> >(responseBody); decimal teacherClassTime = Convert.ToDecimal(TimeSpan.Parse(myProduct.Where(a => a.isTeacher == 1).FirstOrDefault().duration).TotalHours); List <AttendanceReport> students = myProduct.Where(a => a.isTeacher == 0).ToList(); List <AttendenceReportModel> listRep = new List <AttendenceReportModel>(); bool IsProcessed = false; for (int i = 0; i < students.Count; i++) { AttendenceReportModel attenReport = uow.TeacherRepository.GetUserInfo(students[i].userId, id); if (attenReport != null) { IsProcessed = true; decimal dec = Convert.ToDecimal(TimeSpan.Parse(students[i].duration).TotalHours); attenReport.CreditsConsumed = String.Format("{0:0.00}", dec); attenReport.CreditsRefund = String.Format("{0:0.00}", attenReport.CreditsUsed - dec); attenReport.CreditsConsumedInt = dec; attenReport.CreditsRefundInt = attenReport.CreditsUsed - dec; attenReport.StudentClassId = students[i].userId; listRep.Add(attenReport); } } if (IsProcessed == true) { for (int i = 0; i < listRep.Count; i++) { int studentAutoID = listRep[i].StudentClassId; User student = uow.Users.Get(x => x.AutoID == studentAutoID).FirstOrDefault(); StudentClass studentClass = uow.StudentClasses.Get(a => a.StudentID == student.UserID && a.ClassID == id).FirstOrDefault(); if (studentClass != null) { studentClass.Status = (int)ClassJoinStatus.Processed; uow.StudentClasses.Update(studentClass); StudentCreditLog creditLog = new StudentCreditLog { ClassID = id, UserID = studentClass.StudentID, CreationDate = DateTime.Now, CreditsUsed = Math.Round(listRep[i].CreditsRefundInt, 2), LogType = "Refund" }; uow.StudentCreditLogs.Insert(creditLog); StudentCredit credit = uow.StudentCredits.Get(a => a.StudentID == studentClass.StudentID).FirstOrDefault(); if (credit != null) { credit.LastUpdates = DateTime.Now; credit.TotalCredits = credit.TotalCredits + listRep[i].CreditsRefundInt; credit.UsedCredits = credit.UsedCredits - listRep[i].CreditsRefundInt; uow.StudentCredits.Update(credit); } UpdateTutorWallet(classModel.TeacherID, classModel.ClassID, teacherClassTime); //payment refund notification Common.AddNotification("Your wallet has beend refunded with " + creditLog.CreditsUsed, "", Session["UserId"].ToString(), studentClass.StudentID, "/student/wallet", (int)NotificationType.Refund); } } } uow.Save(); } } return(RedirectToAction("classes", "tutor")); }