Esempio n. 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;
            }
        }
Esempio n. 2
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;
            }
        }