private async Task <bool> Upsert(int?TermId, TermViewModel model)
        {
            if (ModelState.IsValid)
            {
                // check the current term

                var helper = (TermId.HasValue ? GetHelper(TermId.Value) : new TermHelper()
                {
                    ServiceUserId = GetUserId()
                });

                if (model.IsCurrentTerm && model.TermId <= 0)
                {
                    var currentTerm = context.Terms.ToList().FirstOrDefault(m => m.IsCurrentTerm);

                    if (currentTerm != null)
                    {
                        if (currentTerm.EndDate > model.StartDate)
                        {
                            ShowError(string.Format("You cannot set new current term starting {0} since Current term ends on {1} ", model.StartDate.ToString("ddd, dd MMM yyyy"), currentTerm.EndDate.ToString("ddd, dd MMM yyyy")));
                            return(false);
                        }

                        if (currentTerm.EndDate > DateTime.Today)
                        {
                            ShowError(string.Format("You cannot set new current term unless the {0} has ended. ", currentTerm.GetTerm()));
                            return(false);
                        }

                        helper.UpdateStudentsOldDebt(currentTerm);
                        currentTerm.IsCurrentTerm        = false;
                        context.Entry(currentTerm).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                if (model.EndDate < UgandaDateTime.DateNow().Date)
                {
                    ShowError("Term End date seems to have passed according to System Calendar.");
                    return(false);
                }

                var upsert = await helper.UpsertTerm(UpsertMode.Admin, model);

                if (upsert.i_RecordId() > 0)
                {
                    ShowSuccess(upsert.ErrorMsg);

                    return(true);
                }
                else
                {
                    ShowError(upsert.ErrorMsg);
                }
            }

            //ParseDefaults(model);
            return(false);
        }
        public void UpdateStudentsOldDebt(Term term)
        {
            var students = db.Students.ToList().Where(p => p.CurrentTermId.HasValue && p.CurrentTermId.Value == term.TermId);

            foreach (var student in students)
            {
                // get outstanding and top up on old debt.
                if (student.HasOutstanding)
                {
                    student.OldDebt         = student.OldDebt + student.TermBalance(term.TermId);
                    student.RegistrationFee = 0;
                    student.Uniforms        = 0;
                    db.Entry(student).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }

            term.Updated = UgandaDateTime.DateNow();
            db.SaveChanges();
        }
Beispiel #3
0
        //
        // GET: /Account/
        public ActionResult Index()
        {
            Session["SearchUsersModel"]    = null;
            Session["SearchPaymentsModel"] = null;
            Session["SearchStudentsModel"] = null;
            Session["SearchParentsModel"]  = null;
            Session["SearchEventsModel"]   = null;
            Session["SearchTermsModel"]    = null;
            Session["SearchClassesModel"]  = null;
            Session["SearchMessagesModel"] = null;
            Session["SearchBanksModel"]    = null;

            var model = new DashboardModel();

            model.Activities = context.Activities
                               .OrderByDescending(o => o.Recorded)
                               .Take(20);

            var term = context.Terms.FirstOrDefault(p => p.IsCurrentTerm);

            model.TermId = term == null ? (int?)null : term.EndDate <= UgandaDateTime.DateNow().Date ? term.TermId : (int?)null;

            return(View(model));
        }
Beispiel #4
0
 public Expense()
 {
     Date = UgandaDateTime.DateNow();
 }
Beispiel #5
0
        //public virtual ApplicationUser User { get; set; }

        //Methods
        public void Update()
        {
            Updated = UgandaDateTime.DateNow();
        }
Beispiel #6
0
 public File()
 {
     //Editors = new List<Editor>();
     DateUploaded = UgandaDateTime.DateNow();
 }