Exemplo n.º 1
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("Успешно добавен запис.");
            }
        }
        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);
            }
        }
 public void MarkChecked(DateTime?date)
 {
     using (var context = new SystemDbContext())
     {
         var checks = context.Set <PeriodicCheck>();
         checks.Add(new PeriodicCheck(date));
         context.SaveChanges();
     }
 }
        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 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);
     }
 }