public String UpdateAlteration(int id, FundsAlteration newAlteration)
        {
            using (var context = new SystemDbContext())
            {
                String msg = "";
                if (!IsValid(newAlteration, UPDATE, out msg))
                {
                    return(msg);
                }

                var fundsAlterations = context.Set <FundsAlteration>();
                var fundsAlteration  = fundsAlterations.Where(x => x.Id == id).FirstOrDefault();
                fundsAlteration.Amount   = newAlteration.Amount;
                fundsAlteration.Comment  = newAlteration.Comment;
                fundsAlteration.Date     = newAlteration.Date;
                fundsAlteration.Type     = newAlteration.Type;
                fundsAlteration.Periodic = newAlteration.Periodic;

                if (!IsValid(fundsAlteration, UPDATE, out msg))
                {
                    return(msg);
                }

                context.SaveChanges();
                return(msg);
            }
        }
Ejemplo n.º 2
0
        public double CalcBalance()
        {
            double balance = 0;

            using (var context = new SystemDbContext())
            {
                var           fundsAlterations = context.Set <FundsAlteration>();
                List <Double> income           = fundsAlterations
                                                 .Where(x => x.Type == FundsAlterationTypes.INCOME)
                                                 .Select(x => x.Amount)
                                                 .ToList();

                List <Double> expense = fundsAlterations
                                        .Where(x => x.Type == FundsAlterationTypes.EXPENSE)
                                        .Select(x => x.Amount)
                                        .ToList();

                foreach (var item in income)
                {
                    balance += item;
                }

                foreach (var item in expense)
                {
                    balance -= item;
                }

                return(balance);
            }
        }
Ejemplo n.º 3
0
        public String AddAlteration(double amount, String type, bool isPeriodic, DateTime?dateTime, String comment = null)
        {
            using (var context = new SystemDbContext())
            {
                if (amount <= 0 ||
                    (!type.Equals(FundsAlterationTypes.INCOME) && !type.Equals(FundsAlterationTypes.EXPENSE)))
                {
                    return("Грешка! Невалидни данни.");
                }

                if (isPeriodic)
                {
                    return("Грешка!"); //to be implemented
                }

                if (type.Equals(FundsAlterationTypes.EXPENSE))
                {
                    double balance = this.CalcBalance();
                    if (amount > balance)
                    {
                        return("Недостатъчни средства!");
                    }
                }

                var      fundsAlterations = context.Set <FundsAlteration>();
                DateTime?dt = (dateTime != null ? dateTime : DateTime.Now);
                fundsAlterations.Add(new FundsAlteration(amount, type, dt, isPeriodic));

                context.SaveChanges();
                return("Успешно добавен запис.");
            }
        }
Ejemplo n.º 4
0
 public List <FundsAlteration> GetAlterations()
 {
     using (var context = new SystemDbContext())
     {
         var fundsAlterations = context.Set <FundsAlteration>();
         return(fundsAlterations.ToList());
     }
 }
 public void MarkChecked(DateTime?date)
 {
     using (var context = new SystemDbContext())
     {
         var checks = context.Set <PeriodicCheck>();
         checks.Add(new PeriodicCheck(date));
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public void DeleteAlteration(int id)
 {
     using (var context = new SystemDbContext())
     {
         var             fundsAlterations = context.Set <FundsAlteration>();
         FundsAlteration fundsAlteration  = fundsAlterations
                                            .Where(x => x.Id == id)
                                            .FirstOrDefault();
         if (fundsAlteration != null)
         {
             fundsAlterations.Remove(fundsAlteration);
         }
     }
 }
        public String AddAlteration(double amount, String type, bool isPeriodic, DateTime?dateTime, String comment = null)
        {
            using (var context = new SystemDbContext())
            {
                var      fundsAlterations = context.Set <FundsAlteration>();
                DateTime?dt = (dateTime != null ? dateTime : DateTime.Now);

                String          msg = "";
                FundsAlteration fa  = new FundsAlteration(amount, type, dt, isPeriodic);
                if (IsValid(fa, CREATE, out msg))
                {
                    fundsAlterations.Add(fa);
                    context.SaveChanges();
                }
                return(msg);
            }
        }
 public bool IsChecked(DateTime?date)
 {
     using (var context = new SystemDbContext())
     {
         var checks     = context.Set <PeriodicCheck>();
         var checkToday = checks
                          .Where(x => x.Date.Value.Year == date.Value.Year &&
                                 x.Date.Value.Month == date.Value.Month &&
                                 x.Date.Value.Day == date.Value.Day)
                          .FirstOrDefault();
         if (checkToday != null)
         {
             return(true);
         }
         return(false);
     }
 }
 public String DeleteAlteration(int id)
 {
     using (var context = new SystemDbContext())
     {
         String          msg = "";
         var             fundsAlterations = context.Set <FundsAlteration>();
         FundsAlteration fundsAlteration  = fundsAlterations
                                            .Where(x => x.Id == id)
                                            .FirstOrDefault();
         if (fundsAlteration != null && IsValid(fundsAlteration, DELETE, out msg))
         {
             fundsAlterations.Remove(fundsAlteration);
         }
         context.SaveChanges();
         return(msg);
     }
 }