Exemple #1
0
        public ActionResult Create(AdmitCardRequestCommand command)
        {
            if (ModelState.IsValid)
            {
                var s = db.StudentInfos.SingleOrDefault(c => c.IdNo == command.IdNo);
                if (s != null)
                {
                    if (!db.Payments.Any(c => c.StudentId == s.IdNo))
                    {
                        ViewBag.Message      = "Your Student Id Not In Payment Table";
                        ViewBag.MessageColor = "text-danger";
                        return(View(command));
                    }


                    var ar = db.AdmitCardRequests.Any(c => c.StudentInfoId == s.Id && !c.IsDone);
                    if (ar)
                    {
                        ViewBag.Message      = "You Already Have Pending Request";
                        ViewBag.MessageColor = "text-danger";
                        return(View(command));
                    }
                    var a = new AdmitCardRequest()
                    {
                        StudentInfoId = s.Id,
                        RequestedDate = DateTimeFormatter.StringToDate(command.RequestedDate),
                        Comment       = command.Comment
                    };

                    db.AdmitCardRequests.Add(a);
                    var r = db.SaveChanges();

                    if (r > 0)
                    {
                        ViewBag.Message      = "Successfully Submitted";
                        ViewBag.MessageColor = "text-success";
                        return(View());
                    }

                    ViewBag.Message      = "Submit Fail";
                    ViewBag.MessageColor = "text-danger";
                    return(View(command));
                }
                else
                {
                    ViewBag.Message      = "ID Not Found";
                    ViewBag.MessageColor = "text-warning";
                }
            }
            ViewBag.Message      = "Submit Valid Value";
            ViewBag.MessageColor = "text-warning";
            return(View(command));
        }
Exemple #2
0
        public JsonResult DueApproval(long stdId, long?requestId, string date, long paymentId)
        {
            var li = db.AdmitCardApprovals.Where(c => c.StudentInfoId == stdId);

            foreach (var ap in li)
            {
                ap.IsPrevious = true;
            }
            db.SaveChanges();

            var stds = db.AdmitCardRequests.Where(c => c.StudentInfoId == stdId);

            foreach (var std in stds)
            {
                std.IsDone = true;
                std.Status = true;
            }
            db.SaveChanges();

            var user = User.Identity.Name;
            var a    = new AdmitCardApproval()
            {
                PaymentId           = paymentId,
                StudentInfoId       = stdId,
                ExceptedDate        = DateTimeFormatter.StringToDate(date),
                IsSpecialPermission = true,
                Comments            = "",
                IsPrevious          = false,
                ApproveBy           = user,
                ApproveDate         = DateTime.Now
            };

            db.AdmitCardApprovals.Add(a);
            var r = db.SaveChanges();

            return(Json(r, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DuePaymentAutoApprove(PaymentUploadVm vm)
        {
            var user = User.Identity.Name;

            ViewBag.ExamId    = new SelectList(db.Exams, "Id", "Name");
            ViewBag.ProgramId = new SelectList(db.Programs, "Id", "ShortName");

            var semester = db.Semesters.SingleOrDefault(c => c.IsActive);

            if (semester == null)
            {
                return(View());
            }

            ViewBag.SemesterId = semester.Id;
            ViewBag.Semester   = semester.Name + " " + semester.Year;

            var entity = db.Payments.Where(c => !c.IsDelete && c.ProgramId == vm.ProgramId && c.SemesterId == vm.SemesterId && c.ExamId == vm.ExamId && c.DuesPercentAmount <= vm.MaxDuePayment && c.DuesPercentAmount >= vm.MinDuePayment).ToList();

            foreach (var p in entity)
            {
                var student = db.StudentInfos.FirstOrDefault(c => c.IdNo == p.StudentId && !c.IsDelete);

                if (student != null)
                {
                    if (db.AdmitCardApprovals.Any(c => c.PaymentId == p.Id && c.IsPaymentComplete))
                    {
                        continue;
                    }

                    var li = db.AdmitCardApprovals.Where(c => c.StudentInfoId == student.Id);
                    foreach (var ap in li)
                    {
                        ap.IsPrevious = true;
                    }
                    db.SaveChanges();


                    var stds = db.AdmitCardRequests.Where(c => c.StudentInfoId == student.Id && !c.IsDone);
                    foreach (var std in stds)
                    {
                        std.IsDone = true;
                        std.Status = true;
                    }
                    db.SaveChanges();

                    var a = new AdmitCardApproval()
                    {
                        PaymentId           = p.Id,
                        StudentInfoId       = student.Id,
                        ExceptedDate        = DateTimeFormatter.StringToDate(vm.PermissionDate),
                        IsSpecialPermission = true,
                        Comments            = "",
                        IsPrevious          = false,
                        ApproveBy           = user,
                        ApproveDate         = DateTime.Now
                    };

                    db.AdmitCardApprovals.Add(a);

                    var r = db.SaveChanges();
                }
            }
            return(Json(1, JsonRequestBehavior.AllowGet));
        }