public ActionResult CommentReply(int CommentHeadId, string UserComment) { var id = User.Identity.GetUserId(); int count = db.AspnetComments.Count(); AspnetComment commentobj = new AspnetComment(); if (count == 0) { commentobj.ParentCommentId = null; commentobj.Comment = UserComment; commentobj.CreationDate = GetLocalDateTime.GetLocalDateTimeFunction(); commentobj.HeadId = CommentHeadId; commentobj.CreatedBy = id; db.AspnetComments.Add(commentobj); db.SaveChanges(); } else { int LastId = db.AspnetComments.OrderByDescending(o => o.Id).FirstOrDefault().Id; commentobj.ParentCommentId = LastId; commentobj.Comment = UserComment; commentobj.CreationDate = GetLocalDateTime.GetLocalDateTimeFunction(); commentobj.HeadId = CommentHeadId; commentobj.CreatedBy = id; db.AspnetComments.Add(commentobj); db.SaveChanges(); } return(Json("", JsonRequestBehavior.AllowGet)); }
}// Student Assignment Submission public ActionResult SaveCommentHead(int LessonID, string Title, string Body) { var id = User.Identity.GetUserId(); AspnetComment_Head commentHead = new AspnetComment_Head(); //Comment_Head commentHead = new Comment_Head(); commentHead.Comment_Head = Title; commentHead.CommentBody = Body; commentHead.LessonId = LessonID; commentHead.CreatedBy = id; commentHead.CreationDate = GetLocalDateTime.GetLocalDateTimeFunction(); db.AspnetComment_Head.Add(commentHead); db.SaveChanges(); return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult StudentFeeUpdate(int id, int ClassId, double RemainingFee = 0, double Discount = 0, double CashReceived = 0, string DueDate = null, string IssueDate = null) { var FeePayable = RemainingFee + Discount + CashReceived; int?sessionId = db.AspNetClasses.Where(x => x.Id == ClassId).FirstOrDefault().SessionID; // db.AspNetSessions.Where(x=>x.Id==) var SessionName = db.AspNetSessions.Where(x => x.Id == sessionId).FirstOrDefault().SessionName; var studenfee = db.StudentFeeMonths.Where(x => x.Id == id).FirstOrDefault(); StudentFeeMonth stdFeeMonth = new StudentFeeMonth(); stdFeeMonth.StudentId = studenfee.StudentId; // stdFeeMonth.IssueDate = DateTime.Now; stdFeeMonth.TotalFee = studenfee.TotalFee; stdFeeMonth.FeePayable = RemainingFee; stdFeeMonth.Discount = Discount; stdFeeMonth.FeeType = studenfee.FeeType; stdFeeMonth.SessionId = sessionId; stdFeeMonth.FeeReceived = CashReceived; DateTime Date = Convert.ToDateTime(DueDate); stdFeeMonth.DueDate = Date; DateTime ConvertedIssueDate = Convert.ToDateTime(IssueDate); stdFeeMonth.IssueDate = ConvertedIssueDate; if (RemainingFee == 0) { stdFeeMonth.Status = "Paid"; } else { stdFeeMonth.Status = "Pending"; } //var Month = DateTime.Now.ToString("MMMM"); var Month = ConvertedIssueDate.ToString("MMMM"); stdFeeMonth.Months = Month; db.StudentFeeMonths.Add(stdFeeMonth); db.SaveChanges(); var idd = User.Identity.GetUserId(); var username = db.AspNetUsers.Where(x => x.Id == idd).Select(x => x.Name).FirstOrDefault(); Voucher voucher = new Voucher(); var UsrId = db.AspNetStudents.Where(x => x.Id == studenfee.StudentId).FirstOrDefault().StudentID; var StudentName = db.AspNetUsers.Where(x => x.Id == UsrId).FirstOrDefault().Name; voucher.Name = "Fee Received by Admin of Student " + StudentName + " Session Name " + SessionName; voucher.Notes = "Fee Received by Admin " + StudentName + " Session Name " + SessionName; voucher.StudentId = studenfee.StudentId; voucher.Date = GetLocalDateTime.GetLocalDateTimeFunction(); voucher.CreatedBy = username; voucher.SessionID = SessionID; int?VoucherObj = db.Vouchers.Max(x => x.VoucherNo); voucher.VoucherNo = Convert.ToInt32(VoucherObj) + 1; db.Vouchers.Add(voucher); db.SaveChanges(); var Leadger = db.Ledgers.Where(x => x.Name == "Account Receiveable").FirstOrDefault(); int AccountReceiveableId = Leadger.Id; decimal? CurrentBalance = Leadger.CurrentBalance; decimal? AfterBalance = 0; VoucherRecord voucherRecord = new VoucherRecord(); if (Discount != 0) { AfterBalance = CurrentBalance - Convert.ToDecimal(CashReceived) - Math.Round(Convert.ToDecimal(Discount)); } else { AfterBalance = CurrentBalance - Convert.ToDecimal(CashReceived); } voucherRecord.LedgerId = AccountReceiveableId; voucherRecord.Type = "Cr"; voucherRecord.Amount = Convert.ToDecimal(CashReceived) + Math.Round(Convert.ToDecimal(Discount)); voucherRecord.CurrentBalance = CurrentBalance; voucherRecord.AfterBalance = AfterBalance; voucherRecord.VoucherId = voucher.Id; voucherRecord.Description = "Fee received of Student (" + StudentName + ") (" + SessionName + ") "; Leadger.CurrentBalance = AfterBalance; try { db.VoucherRecords.Add(voucherRecord); db.SaveChanges(); } catch (Exception ex) { var a = ex.Message; } var LeadgerAD = db.Ledgers.Where(x => x.Name == "Admin Drawer").FirstOrDefault(); int AdminDrawerId = LeadgerAD.Id; decimal?CurrentBalanceAD = LeadgerAD.CurrentBalance; VoucherRecord voucherRecord1 = new VoucherRecord(); decimal? AfterBalanceAD = CurrentBalanceAD + Convert.ToDecimal(CashReceived); voucherRecord1.LedgerId = AdminDrawerId; voucherRecord1.Type = "Dr"; voucherRecord1.Amount = Convert.ToDecimal(CashReceived); voucherRecord1.CurrentBalance = CurrentBalanceAD; voucherRecord1.AfterBalance = AfterBalanceAD; voucherRecord1.VoucherId = voucher.Id; voucherRecord1.Description = "Fee Collected by student (" + StudentName + ") (" + SessionName + ") "; LeadgerAD.CurrentBalance = AfterBalanceAD; db.VoucherRecords.Add(voucherRecord1); db.SaveChanges(); if (Discount != 0) { VoucherRecord voucherRecord3 = new VoucherRecord(); var LeadgerDiscount = db.Ledgers.Where(x => x.Name == "Discount").FirstOrDefault(); decimal?CurrentBalanceOfDiscount = LeadgerDiscount.CurrentBalance; decimal?AfterBalanceOfDiscount = CurrentBalanceOfDiscount + Math.Round(Convert.ToDecimal(Discount)); voucherRecord3.LedgerId = LeadgerDiscount.Id; voucherRecord3.Type = "Dr"; voucherRecord3.Amount = Math.Round(Convert.ToDecimal(Discount)); voucherRecord3.CurrentBalance = CurrentBalanceOfDiscount; voucherRecord3.AfterBalance = AfterBalanceOfDiscount; voucherRecord3.VoucherId = voucher.Id; voucherRecord3.Description = "Discount given to student (" + StudentName + ") (" + SessionName + ") on payable fee " + FeePayable; LeadgerDiscount.CurrentBalance = AfterBalanceOfDiscount; db.VoucherRecords.Add(voucherRecord3); db.SaveChanges(); } return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult ChangeStatus(int Id) { var StudentFeeMonthToUpdate = db.StudentFeeMonths.Where(x => x.Id == Id).FirstOrDefault(); StudentFeeMonthToUpdate.Status = "Paid"; db.SaveChanges(); var id = User.Identity.GetUserId(); var username = db.AspNetUsers.Where(x => x.Id == id).Select(x => x.Name).FirstOrDefault(); Voucher voucher = new Voucher(); voucher.Name = "Student Fee Clear"; voucher.Notes = "Student Fee Clear"; voucher.Date = GetLocalDateTime.GetLocalDateTimeFunction(); voucher.CreatedBy = username; voucher.SessionID = SessionID; int?VoucherObj = db.Vouchers.Max(x => x.VoucherNo); voucher.VoucherNo = Convert.ToInt32(VoucherObj) + 1; db.Vouchers.Add(voucher); db.SaveChanges(); var Leadger = db.Ledgers.Where(x => x.Name == "Account Receiveable").FirstOrDefault(); int AccountRecId = Leadger.Id; decimal?CurrentBalance = Leadger.CurrentBalance; VoucherRecord voucherRecord = new VoucherRecord(); decimal? AfterBalance = CurrentBalance - Convert.ToDecimal(StudentFeeMonthToUpdate.FeePayable); voucherRecord.LedgerId = AccountRecId; voucherRecord.Type = "Cr"; voucherRecord.Amount = Convert.ToDecimal(StudentFeeMonthToUpdate.FeePayable); voucherRecord.CurrentBalance = CurrentBalance; voucherRecord.AfterBalance = AfterBalance; voucherRecord.VoucherId = voucher.Id; voucherRecord.Description = "Student Fee Credit in Account Receiveable"; Leadger.CurrentBalance = AfterBalance; db.VoucherRecords.Add(voucherRecord); db.SaveChanges(); //Second; VoucherRecord voucherRecord1 = new VoucherRecord(); var LeadgerAdminDrawer = db.Ledgers.Where(x => x.Name == "Admin Drawer").FirstOrDefault(); decimal?CurrentBalanceOfAdminDrawer = LeadgerAdminDrawer.CurrentBalance; decimal?AfterBalanceOfAdminDrawer = CurrentBalanceOfAdminDrawer + Convert.ToDecimal(StudentFeeMonthToUpdate.FeePayable); voucherRecord1.LedgerId = LeadgerAdminDrawer.Id; voucherRecord1.Type = "Dr"; voucherRecord1.Amount = Convert.ToDecimal(StudentFeeMonthToUpdate.FeePayable); voucherRecord1.CurrentBalance = CurrentBalanceOfAdminDrawer; voucherRecord1.AfterBalance = AfterBalanceOfAdminDrawer; voucherRecord1.VoucherId = voucher.Id; voucherRecord1.Description = "Student Fee Debit in Admin Drawr"; LeadgerAdminDrawer.CurrentBalance = AfterBalanceOfAdminDrawer; db.VoucherRecords.Add(voucherRecord1); db.SaveChanges(); return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult ApproveOrders(int OrderId, string OrderType) { AspNetOrder OrderToModify = db.AspNetOrders.Where(x => x.Id == OrderId).FirstOrDefault(); OrderToModify.Status = "Paid"; db.Entry(OrderToModify).State = EntityState.Modified; db.SaveChanges(); List <AspNetNotesOrder> NotesOrderToModify = db.AspNetNotesOrders.Where(x => x.OrderId == OrderId).ToList(); foreach (var NotesOrder in NotesOrderToModify) { NotesOrder.Status = "Paid"; db.Entry(NotesOrder).State = EntityState.Modified; db.SaveChanges(); } var result = from Notes in db.AspNetNotes join OrderNotes in db.AspNetNotesOrders on Notes.Id equals OrderNotes.NotesID join Order in db.AspNetOrders on OrderNotes.OrderId equals Order.Id join Student in db.AspNetStudents on OrderNotes.StudentID equals Student.Id join User in db.AspNetUsers on Student.StudentID equals User.Id where Order.Id == OrderId select new { classId = Student.ClassID, Title = Notes.Title, Quantity = OrderNotes.Quantity, GrandTotal = Notes.GrandTotal, PhotoCopier = Notes.PhotoCopierPrice, NameOfStudent = User.Name, StudentId = Student.Id, TotalPhotoCopierPrice = (Notes.PhotoCopierPrice * OrderNotes.Quantity) }; var NameOfStudent = result.FirstOrDefault().NameOfStudent; var classIdd = result.FirstOrDefault().classId; var SessionIdd = db.AspNetClasses.Where(x => x.Id == classIdd).FirstOrDefault().SessionID; var SessionName = db.AspNetSessions.Where(x => x.Id == SessionIdd).FirstOrDefault().SessionName; double TotalPriceOfPhotoCopier = 0; foreach (var item in result) { TotalPriceOfPhotoCopier = Convert.ToDouble(TotalPriceOfPhotoCopier + item.TotalPhotoCopierPrice); } var id = User.Identity.GetUserId(); var username = db.AspNetUsers.Where(x => x.Id == id).Select(x => x.Name).FirstOrDefault(); Voucher voucher = new Voucher(); voucher.Name = "Notes paid by Student " + NameOfStudent + " Session Name " + SessionName; voucher.Notes = "Cash received for notes"; voucher.Date = GetLocalDateTime.GetLocalDateTimeFunction(); voucher.StudentId = result.FirstOrDefault().StudentId; voucher.CreatedBy = username; voucher.SessionID = SessionID; int?VoucherObj = db.Vouchers.Max(x => x.VoucherNo); voucher.VoucherNo = Convert.ToInt32(VoucherObj) + 1; db.Vouchers.Add(voucher); db.SaveChanges(); if (OrderType == "Postpaid") { var Leadger = db.Ledgers.Where(x => x.Name == "Admin Drawer").FirstOrDefault(); int AdminDrawerId = Leadger.Id; decimal? CurrentBalance = Leadger.CurrentBalance; VoucherRecord voucherRecord = new VoucherRecord(); decimal? AfterBalance = CurrentBalance + OrderToModify.TotalAmount; voucherRecord.LedgerId = AdminDrawerId; voucherRecord.Type = "Dr"; voucherRecord.Amount = OrderToModify.TotalAmount; voucherRecord.CurrentBalance = CurrentBalance; voucherRecord.AfterBalance = AfterBalance; voucherRecord.VoucherId = voucher.Id; voucherRecord.Description = "Notes paid by student (" + NameOfStudent + ") (" + SessionName + ")"; Leadger.CurrentBalance = AfterBalance; db.VoucherRecords.Add(voucherRecord); db.SaveChanges(); VoucherRecord voucherRecord1 = new VoucherRecord(); var LeadgerNotes = db.Ledgers.Where(x => x.Name == "Notes").FirstOrDefault(); decimal?CurrentBalanceOfNotes = LeadgerNotes.CurrentBalance; decimal?AfterBalanceOfNotes = CurrentBalanceOfNotes + OrderToModify.TotalAmount; voucherRecord1.LedgerId = LeadgerNotes.Id; voucherRecord1.Type = "Cr"; voucherRecord1.Amount = OrderToModify.TotalAmount; voucherRecord1.CurrentBalance = CurrentBalanceOfNotes; voucherRecord1.AfterBalance = AfterBalanceOfNotes; voucherRecord1.VoucherId = voucher.Id; voucherRecord1.Description = "Notes against order ID " + OrderId; LeadgerNotes.CurrentBalance = AfterBalanceOfNotes; db.VoucherRecords.Add(voucherRecord1); db.SaveChanges(); }//end of if VoucherRecord voucherRecord2 = new VoucherRecord(); var IdofLedger = from Ledger in db.Ledgers join LedgerHd in db.LedgerHeads on Ledger.LedgerHeadId equals LedgerHd.Id where LedgerHd.Name == "Liabilities" && Ledger.Name == "Photocopier" select new { Ledger.Id }; int photoCopierId = Convert.ToInt32(IdofLedger.FirstOrDefault().Id); var LeadgerPhotoCopierL = db.Ledgers.Where(x => x.Id == photoCopierId).FirstOrDefault(); decimal?CurrentBalanceOfPhotoCopiter = LeadgerPhotoCopierL.CurrentBalance; decimal?AfterBalanceOfPhotoCopier = CurrentBalanceOfPhotoCopiter + Convert.ToDecimal(TotalPriceOfPhotoCopier); voucherRecord2.LedgerId = LeadgerPhotoCopierL.Id; voucherRecord2.Type = "Cr"; voucherRecord2.Amount = Convert.ToDecimal(TotalPriceOfPhotoCopier); voucherRecord2.CurrentBalance = CurrentBalanceOfPhotoCopiter; voucherRecord2.AfterBalance = AfterBalanceOfPhotoCopier; voucherRecord2.VoucherId = voucher.Id; voucherRecord2.Description = "Notes against order ID " + OrderId; LeadgerPhotoCopierL.CurrentBalance = AfterBalanceOfPhotoCopier; db.VoucherRecords.Add(voucherRecord2); db.SaveChanges(); VoucherRecord voucherRecord3 = new VoucherRecord(); var IdofLedger1 = from Ledger in db.Ledgers join LedgerHd in db.LedgerHeads on Ledger.LedgerHeadId equals LedgerHd.Id where LedgerHd.Name == "Expense" && Ledger.Name == "Photocopier" select new { Ledger.Id }; int photoCopierIdOfExpense = Convert.ToInt32(IdofLedger1.FirstOrDefault().Id); var LeadgerPhotoCopierE = db.Ledgers.Where(x => x.Id == photoCopierIdOfExpense).FirstOrDefault(); decimal?CurrentBalanceOfPhotoCopiterE = LeadgerPhotoCopierE.CurrentBalance; decimal?AfterBalanceOfPhotoCopierE = CurrentBalanceOfPhotoCopiterE + Convert.ToDecimal(TotalPriceOfPhotoCopier); voucherRecord3.LedgerId = LeadgerPhotoCopierE.Id; voucherRecord3.Type = "Dr"; voucherRecord3.Amount = Convert.ToDecimal(TotalPriceOfPhotoCopier); voucherRecord3.CurrentBalance = CurrentBalanceOfPhotoCopiterE; voucherRecord3.AfterBalance = AfterBalanceOfPhotoCopierE; voucherRecord3.VoucherId = voucher.Id; voucherRecord3.Description = "Notes against order ID " + OrderId; LeadgerPhotoCopierE.CurrentBalance = AfterBalanceOfPhotoCopierE; db.VoucherRecords.Add(voucherRecord3); db.SaveChanges(); return(Json("", JsonRequestBehavior.AllowGet)); }
}// Student Assignment Submission public ActionResult SaveCommentHead(int LessonID, string Title, string Body) { var id = User.Identity.GetUserId(); AspnetComment_Head commentHead = new AspnetComment_Head(); string EncrID = LessonID + Title + Body + id; commentHead.EncryptedID = Encrpt.Encrypt(EncrID, true); var newString = Regex.Replace(commentHead.EncryptedID, @"[^0-9a-zA-Z]+", "s"); string str = newString.Substring(0, 32); commentHead.EncryptedID = str; //Comment_Head commentHead = new Comment_Head(); commentHead.Comment_Head = Title; commentHead.CommentBody = Body; commentHead.LessonId = LessonID; commentHead.CreatedBy = id; commentHead.CreationDate = GetLocalDateTime.GetLocalDateTimeFunction(); db.AspnetComment_Head.Add(commentHead); db.SaveChanges(); var UserId = User.Identity.GetUserId(); var UserName = db.AspNetUsers.Where(x => x.Id == UserId).FirstOrDefault().Name; var NotificationObj = new AspNetNotification(); NotificationObj.Description = UserName + " asked a Question"; NotificationObj.Subject = "Student Comment "; NotificationObj.SenderID = UserId; NotificationObj.Time = GetLocalDateTime.GetLocalDateTimeFunction(); NotificationObj.Url = "/TeacherCommentsOnCourses/CommentsPage1/" + commentHead.Id; db.AspNetNotifications.Add(NotificationObj); db.SaveChanges(); int?TopicId = db.AspnetLessons.Where(x => x.Id == LessonID).FirstOrDefault().TopicId; int?SubjectId = db.AspnetSubjectTopics.Where(x => x.Id == TopicId).FirstOrDefault().SubjectId; var AllTeachers = db.Teacher_GenericSubjects.Where(x => x.SubjectId == SubjectId).Select(x => x.TeacherId); var UnionTeachers = AllTeachers.Distinct(); var AllEmployeesUserId = from employee in db.AspNetEmployees where AllTeachers.Contains(employee.Id) select new { employee.UserId, }; SEA_DatabaseEntities db2 = new SEA_DatabaseEntities(); foreach (var receiver in AllEmployeesUserId) { var notificationRecieve = new AspNetNotification_User(); notificationRecieve.NotificationID = NotificationObj.Id; notificationRecieve.UserID = Convert.ToString(receiver.UserId); notificationRecieve.Seen = false; db2.AspNetNotification_User.Add(notificationRecieve); try { db2.SaveChanges(); } catch (Exception ex) { var Msg = ex.Message; } } return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult CommentReply(int CommentHeadId, string UserComment) { var id = User.Identity.GetUserId(); int count = db.AspnetComments.Count(); AspnetComment commentobj = new AspnetComment(); if (count == 0) { commentobj.ParentCommentId = null; commentobj.Comment = UserComment; commentobj.CreationDate = GetLocalDateTime.GetLocalDateTimeFunction(); commentobj.HeadId = CommentHeadId; commentobj.CreatedBy = id; db.AspnetComments.Add(commentobj); db.SaveChanges(); } else { int LastId = db.AspnetComments.OrderByDescending(o => o.Id).FirstOrDefault().Id; commentobj.ParentCommentId = LastId; commentobj.Comment = UserComment; commentobj.CreationDate = GetLocalDateTime.GetLocalDateTimeFunction(); commentobj.HeadId = CommentHeadId; commentobj.CreatedBy = id; db.AspnetComments.Add(commentobj); db.SaveChanges(); } var UserNameLog = User.Identity.Name; AspNetUser currentUser = db.AspNetUsers.First(x => x.UserName == UserNameLog); var UserId = User.Identity.GetUserId(); var UserName = db.AspNetUsers.Where(x => x.Id == UserId).FirstOrDefault().Name; var NotificationObj = new AspNetNotification(); NotificationObj.Description = "Teacher " + UserName + " Replied"; NotificationObj.Subject = "Reply To Student Comment"; NotificationObj.SenderID = UserId; NotificationObj.Time = GetLocalDateTime.GetLocalDateTimeFunction(); NotificationObj.Url = "/StudentCourses/CommentsPage1/" + CommentHeadId; db.AspNetNotifications.Add(NotificationObj); db.SaveChanges(); //int? LessonID = db.AspnetComment_Head.Where(x => x.Id == CommentHeadId).FirstOrDefault().LessonId; //int? TopicId = db.AspnetLessons.Where(x => x.Id == LessonID).FirstOrDefault().TopicId; //int? SubjectId = db.AspnetSubjectTopics.Where(x => x.Id == TopicId).FirstOrDefault().SubjectId; //var AllStudents = db.Student_GenericSubjects.Where(x => x.GenericSubjectId == SubjectId).Select(x => x.StudentId); //var DistinctStudents = AllStudents.Distinct(); //foreach (var receiver in DistinctStudents) //{ var receiver = db.AspnetComment_Head.Where(x => x.Id == CommentHeadId).Select(x => x.CreatedBy).FirstOrDefault(); SEA_DatabaseEntities db2 = new SEA_DatabaseEntities(); var notificationRecieve = new AspNetNotification_User(); notificationRecieve.NotificationID = NotificationObj.Id; notificationRecieve.UserID = Convert.ToString(receiver); notificationRecieve.Seen = false; db2.AspNetNotification_User.Add(notificationRecieve); db2.SaveChanges(); // } return(Json("", JsonRequestBehavior.AllowGet)); }
public ActionResult AddCashVoucher(_Voucher Vouchers) { try { var LeadgerAdminDrawer = db.Ledgers.Where(x => x.Name == "Admin Drawer").FirstOrDefault(); decimal?CurrentBalanceOfAdminDrawer = LeadgerAdminDrawer.CurrentBalance; decimal Total = Convert.ToDecimal(Vouchers.uppertotal); if (CurrentBalanceOfAdminDrawer > Total) { string[] D4 = Vouchers.Time.Split('-'); Vouchers.Time = D4[2] + "/" + D4[1] + "/" + D4[0]; Voucher v = new Voucher(); var localtime = DateTime.Now.ToLocalTime().ToString(); var time = localtime.Split(' '); var timestamps = time[1].Split(':'); if (timestamps[0].Count() == 1) { timestamps[0] = "0" + timestamps[0]; } if (timestamps[1].Count() == 1) { timestamps[1] = "0" + timestamps[1]; } if (timestamps[2].Count() == 1) { timestamps[2] = "0" + timestamps[2]; } time[1] = timestamps[0] + ":" + timestamps[1] + ":" + timestamps[2]; var date = Vouchers.Time + " " + time[1] + " " + time[2]; // DateTime dt = //DateTime.ParseExact(date, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture); v.Date = GetLocalDateTime.GetLocalDateTimeFunction(); v.Notes = Vouchers.Narration; v.VoucherNo = Vouchers.VoucherNo; v.Name = Vouchers.VoucherName; var id = User.Identity.GetUserId(); v.SessionID = SessionID; var username = db.AspNetUsers.Where(x => x.Id == id).Select(x => x.Name).FirstOrDefault(); v.CreatedBy = username; db.Vouchers.Add(v); db.SaveChanges(); foreach (Voucher_Detail voucher in Vouchers.VoucherDetail) { VoucherRecord VR = new VoucherRecord(); int idd = Convert.ToInt32(voucher.Code); var Ledger = db.Ledgers.Where(x => x.Id == idd).FirstOrDefault(); decimal?CurrentBlance = Ledger.CurrentBalance; decimal?AfterBalanceOfLedger = CurrentBlance + Convert.ToDecimal(voucher.Credit); VR.LedgerId = idd; VR.Type = "Dr"; VR.Amount = Convert.ToDecimal(voucher.Credit); VR.CurrentBalance = CurrentBlance; VR.AfterBalance = AfterBalanceOfLedger; VR.VoucherId = v.Id; VR.Description = voucher.Transaction; Ledger.CurrentBalance = AfterBalanceOfLedger; db.VoucherRecords.Add(VR); db.SaveChanges(); } var LeadgerAdminDrawer1 = db.Ledgers.Where(x => x.Name == "Admin Drawer").FirstOrDefault(); decimal?CurrentBalanceOfAdminDrawer1 = LeadgerAdminDrawer1.CurrentBalance; decimal? AfterBalanceOfAdminDrawer1 = CurrentBalanceOfAdminDrawer1 - Convert.ToDecimal(Vouchers.uppertotal); VoucherRecord voucherRecord1 = new VoucherRecord(); voucherRecord1.LedgerId = LeadgerAdminDrawer.Id; voucherRecord1.Type = "Cr"; voucherRecord1.Amount = Convert.ToDecimal(Vouchers.uppertotal); voucherRecord1.CurrentBalance = CurrentBalanceOfAdminDrawer; voucherRecord1.AfterBalance = AfterBalanceOfAdminDrawer1; voucherRecord1.VoucherId = v.Id; voucherRecord1.Description = "Expense Credited"; LeadgerAdminDrawer1.CurrentBalance = AfterBalanceOfAdminDrawer1; db.VoucherRecords.Add(voucherRecord1); db.SaveChanges(); var result = "yes"; return(Json(result, JsonRequestBehavior.AllowGet)); } else { var result = "No"; return(Json(result, JsonRequestBehavior.AllowGet)); } } catch { } return(RedirectToAction("Cash")); }