public void Clear()
 {
     using (Context.AppContext dbContext = new Context.AppContext())
     {
         //TODO
     }
 }
        public List <CostModel> GetCosts()
        {
            List <CostModel> costs = null;

            Context.AppContext dbContext = new Context.AppContext();
            try
            {
                costs = dbContext.Costs.ToList();
            }
            catch (SqliteException ex)
            {
                dbContext.Database.ExecuteSqlCommand("alter table Costs add BalanceId text null;");
                dbContext.Database.ExecuteSqlCommand("alter table Balance add Name text null;");
                dbContext.Database.ExecuteSqlCommand("update Balance set Name = 'My first account'");

                var firstBalance = dbContext.Balance.First();
                dbContext.Database.ExecuteSqlCommand($"update Costs set BalanceId={firstBalance.Id};");

                costs = dbContext.Costs.ToList();
            }
            finally
            {
                if (dbContext != null)
                {
                    dbContext.Dispose();
                }
            }

            costs.Reverse();

            return(costs);
        }
 public void RemoveCost(CostModel cost)
 {
     using (Context.AppContext dbContext = new Context.AppContext())
     {
         dbContext.Costs.Remove(cost);
         dbContext.SaveChanges();
     }
 }
 public void RemoveCategory(CategoryModel category)
 {
     using (Context.AppContext dbContext = new Context.AppContext())
     {
         dbContext.Categories.Remove(category);
         dbContext.SaveChanges();
     }
 }
 public void RemoveBalance(BalanceModel balance)
 {
     using (Context.AppContext dbContext = new Context.AppContext())
     {
         dbContext.Balance.Remove(balance);
         dbContext.SaveChanges();
     }
 }
 internal void UpdateCost(CostModel updateCost)
 {
     using (Context.AppContext dbContext = new Context.AppContext())
     {
         CostModel currentCost = dbContext.Costs.FirstOrDefault(c => c.Id == updateCost.Id);
         dbContext.Entry(currentCost).CurrentValues.SetValues(updateCost);
         dbContext.SaveChanges();
     }
 }
 internal void UpdateCategory(CategoryModel updateCategory)
 {
     using (Context.AppContext dbContext = new Context.AppContext())
     {
         CategoryModel currentCategory = dbContext.Categories.FirstOrDefault(c => c.Id == updateCategory.Id);
         dbContext.Entry(currentCategory).CurrentValues.SetValues(updateCategory);
         dbContext.SaveChanges();
     }
 }
 internal void UpdateBalance(BalanceModel updateBalance)
 {
     using (Context.AppContext dbContext = new Context.AppContext())
     {
         BalanceModel currentBalance = dbContext.Balance.FirstOrDefault(b => b.Id == updateBalance.Id);
         dbContext.Entry(currentBalance).CurrentValues.SetValues(updateBalance);
         dbContext.SaveChanges();
     }
 }
        internal CostModel GetCost(string id)
        {
            CostModel result = null;

            using (Context.AppContext dbContext = new Context.AppContext())
            {
                result = dbContext.Costs.FirstOrDefault(c => c.Id == id);
            }

            return(result);
        }
        public List <CategoryModel> GetCategories()
        {
            List <CategoryModel> categories = null;

            using (Context.AppContext dbContext = new Context.AppContext())
            {
                categories = new List <CategoryModel>(dbContext.Categories);
            }

            return(categories);
        }
        /// <summary>
        /// Return a cost begin with count
        /// </summary>
        /// <param name="count">Count is a start index</param>
        /// <returns></returns>
        internal IEnumerable <CostModel> GetCosts(int count)
        {
            List <CostModel> costs = null;

            using (Context.AppContext dbContext = new Context.AppContext())
            {
                var allCost = new List <CostModel>(dbContext.Costs);
                allCost.Reverse();
                costs = new List <CostModel>(allCost.Skip(count).Take(COSTS_COUNT));
            }

            return(costs);
        }
Exemple #12
0
        public Context.AppContext Init()
        {
            Context.AppContext appContext = _dbContext;

            if (appContext != null)
            {
                return(appContext);
            }

            Context.AppContext appContext1 = new Context.AppContext();
            Context.AppContext appContext2 = appContext1;

            _dbContext = appContext1;
            appContext = appContext2;

            return(appContext);
        }
        protected override void Seed(Context.AppContext context)
        {
            //  This method will be called after migrating to the latest version.

            context.Restaurants.AddOrUpdate(x => x.Name,
                                            new Restaurant("Registro 1")
                                            );


            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
        public BalanceModel GetFirstBalance()
        {
            BalanceModel balance = null;

            Context.AppContext dbContext = new Context.AppContext();
            try
            {
                balance = dbContext.Balance.FirstOrDefault();
            }
            catch (SqliteException ex)
            {
                dbContext.Database.ExecuteSqlCommand("alter table Balance add Name text null;");
                balance = dbContext.Balance.FirstOrDefault();
            }
            finally
            {
                if (dbContext != null)
                {
                    dbContext.Dispose();
                }
            }

            return(balance);
        }
        public List <BalanceModel> GetBalances()
        {
            List <BalanceModel> balances = null;

            Context.AppContext dbContext = new Context.AppContext();
            try
            {
                balances = dbContext.Balance.ToList();
            }
            catch (SqliteException ex)
            {
                dbContext.Database.ExecuteSqlCommand("alter table Balance add Name text null;");
                dbContext.Database.ExecuteSqlCommand("update Balance set Name = 'My first account'");
            }
            finally
            {
                if (dbContext != null)
                {
                    dbContext.Dispose();
                }
            }

            return(balances);
        }
 public CartController(Context.AppContext context)
 {
     db = context;
 }
Exemple #17
0
 // CONSTRUCTORS
 /// <summary>
 /// Initialize a new instance of <see cref="PhotoLikeRepository"/>
 /// </summary>
 /// <param name="context">Data context</param>
 public PhotoLikeRepository(Context.AppContext context)
     : base(context)
 {
 }
 public FileRepo(Context.AppContext context)
 {
     _context = context;
 }
Exemple #19
0
 public ProductController(Context.AppContext context)
 {
     db = context;
 }
 // CONSTRUCTORS
 /// <summary>
 /// Initialize a new instance of <see cref="MessageRepository"/>
 /// </summary>
 /// <param name="context">Data context</param>
 public MessageRepository(Context.AppContext context)
     : base(context)
 {
 }
 // CONSTRUCTORS
 /// <summary>
 /// Initialize a new instance of <see cref="SubjectRepository"/>
 /// </summary>
 /// <param name="context">Data context</param>
 public SubjectRepository(Context.AppContext context)
     : base(context)
 {
 }
 public BaseRepository()
 {
     _context = new Context.AppContext();
     DbSet    = _context.Set <TEntity>();
 }
 // CONSTRUCTORS
 /// <summary>
 /// Initializes a new instance of <see cref="NonGenericRepository"/>
 /// </summary>
 /// <param name="context">
 /// Data context
 /// </param>
 /// <param name="entityType">
 /// Entity type
 /// </param>
 public NonGenericRepository(Context.AppContext context, Type entityType)
 {
     this.context = context;
     this.dbSet   = context.Set(entityType);
 }
Exemple #24
0
 public WishListController(Context.AppContext context)
 {
     db = context;
 }
 public CategoriesController(Context.AppContext context)
 {
     db = context;
 }
 // CONSTRUCTORS
 /// <summary>
 /// Initializes a new instance of <see cref="UserRepository"/>
 /// </summary>
 /// <param name="context">Data context</param>
 public UserRepository(Context.AppContext context)
     : base(context)
 {
 }
 // CONSTRUCTORS
 /// <summary>
 /// Initialize a new instance of <see cref="CommentRepository"/>
 /// </summary>
 /// <param name="context">Data context</param>
 public CommentRepository(Context.AppContext context)
     : base(context)
 {
 }
Exemple #28
0
 //construtor
 public ProdutoTestSteps()
 {
     appContext = new Context.AppContext();
     resource   = "/api/Produto";
 }
Exemple #29
0
 public UserController(Context.AppContext context)
 {
     this.context = context;
 }
Exemple #30
0
 public OrderController(Context.AppContext context)
 {
     db = context;
 }