Пример #1
0
        /// <summary>
        /// Updates existing Payment in Database
        /// </summary>
        /// <param name="payment">Payment to Update</param>
        /// <returns>Count of affected rows in database</returns>
        public static int Update(Payment payment)
        {
            int c = 0;

            try
            {
                using (var db = new PaymentsContext())
                {
                    db.Payments.Attach(payment);
                    db.Entry(payment).State = EntityState.Modified;
                    c = db.SaveChanges();
                }

                if (c < 1)
                {
                    throw new Exception("Update<Payment>() failed to update payment's details!");
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        /// <summary>
        /// Delete Payment from Database
        /// </summary>
        /// <param name="payment">Payment to Delete</param>
        /// <returns>Count of affected rows in database</returns>
        public static int Delete(Payment payment)
        {
            int c = 0;

            try
            {
                using (var db = new PaymentsContext())
                {
                    db.Payments.Attach(payment);
                    db.Payments.Remove(payment);
                    c = db.SaveChanges();
                }

                if (c < 1)
                {
                    throw new Exception("Delete<Payment>() failed to delete payment!");
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        /// <summary>
        /// Updates existing Category in Database
        /// </summary>
        /// <param name="category">Category to Update</param>
        /// <returns>Count of affected rows in database</returns>
        public static int Update(Category category)
        {
            int c = 0;

            try
            {
                using (var db = new PaymentsContext())
                {
                    db.Categories.Attach(category);
                    db.Entry(category).State = EntityState.Modified;
                    c = db.SaveChanges();
                }

                if (c < 1)
                {
                    throw new Exception("Update<Category>() failed to update category's details!");
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        /// <summary>
        /// Delete Category with sub categories from Database
        /// </summary>
        /// <param name="category">Category to Delete</param>
        /// <returns>Count of affected rows in database</returns>
        public static int Delete(Category category)
        {
            int c = 0;

            try
            {
                using (var db = new PaymentsContext())
                {
                    var subCategories = db.Categories.Where(p => p.ParentId == category.Id);

                    foreach (var subCategory in subCategories)
                    {
                        db.Categories.Attach(subCategory);
                        db.Categories.Remove(subCategory);
                    }

                    db.Categories.Attach(category);
                    db.Categories.Remove(category);
                    c = db.SaveChanges();
                }

                if (c < 1)
                {
                    throw new Exception("Delete<Category>() failed to delete category!");
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
        /// <summary>
        /// Delete User from Database
        /// </summary>
        /// <param name="user">User to Delete</param>
        /// <returns>Count of affected rows in database</returns>
        public static int Delete(User user)
        {
            int c = 0;

            try
            {
                using (var db = new PaymentsContext())
                {
                    db.Users.Attach(user);
                    db.Users.Remove(user);
                    c = db.SaveChanges();
                }

                if (c < 1)
                {
                    throw new Exception("Delete<User>() failed to delete user!");
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
        /// <summary>
        /// Creates new Payment to Database
        /// </summary>
        /// <param name="payment">Payment to Create</param>
        /// <returns>Count of affected rows in database</returns>
        public static int Create(Payment payment)
        {
            int c = 0;

            try
            {
                using (var db = new PaymentsContext())
                {
                    db.Payments.Add(payment);
                    c = db.SaveChanges();
                }

                if (c < 1)
                {
                    throw new Exception("Create<Payment>() failed to create new payment!");
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #7
0
        /// <summary>
        /// Creates new Category to Database
        /// </summary>
        /// <param name="category">Category to Create</param>
        /// <returns>Count of affected rows in database</returns>
        public static int Create(Category category)
        {
            int c = 0;

            try
            {
                using (var db = new PaymentsContext())
                {
                    db.Categories.Add(category);
                    c = db.SaveChanges();
                }

                if (c < 1)
                {
                    throw new Exception("Create<Category>() failed to create new category!");
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #8
0
        /// <summary>
        /// Creates new User to Database
        /// </summary>
        /// <param name="user">User to Create</param>
        /// <returns>Count of affected rows in database</returns>
        public static int Create(User user)
        {
            int c = 0;

            try
            {
                using (var db = new PaymentsContext())
                {
                    db.Users.Add(user);
                    c = db.SaveChanges();
                }

                if (c < 1)
                {
                    throw new Exception("Create<User>() failed to create new user!");
                }

                return(c);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }