Пример #1
0
 public void CleanRepository()
 {
     using (var context = new ExpensesContext())
     {
         context.Expenses.RemoveRange(context.Expenses);
         context.SaveChanges();
     }
 }
Пример #2
0
 public DbExpense SaveExpense(DbExpense expense)
 {
     using (var context = new ExpensesContext())
     {
         context.Expenses.Add(expense);
         context.SaveChanges();
         return expense;
     }
 }
        public void CleanRepository()
        {
            using (var context = new ExpensesContext())
            {
                context.Charges.RemoveRange(context.Charges);
                context.Reports.RemoveRange(context.Reports);
                context.Employees.RemoveRange(context.Employees);

                context.SaveChanges();
            }
        }
 public void DeleteExpenseReport(int reportId)
 {
     using (var context = new ExpensesContext())
     {
         var report = context.Reports.SingleOrDefault(i => i.ExpenseReportId == reportId);
         if (report != null)
         {
             context.Reports.Remove(report);
             context.SaveChanges();
         }
     }
 }
 public void DeleteCharge(int chargeId)
 {
     using (var context = new ExpensesContext())
     {
         var charge = context.Charges.SingleOrDefault(i => i.ChargeId == chargeId);
         if (charge != null)
         {
             context.Charges.Remove(charge);
             context.SaveChanges();
         }
     }
 }
 public void DeleteCharge(int chargeId)
 {
     using (var context = new ExpensesContext())
     {
         var charge = context.Charges.SingleOrDefault(i => i.ChargeId == chargeId);
         if (charge != null)
         {
             context.Charges.Remove(charge);
             context.SaveChanges();
         }
     }
 }
 public void DeleteExpenseReport(int reportId)
 {
     using (var context = new ExpensesContext())
     {
         var report = context.Reports.SingleOrDefault(i => i.ExpenseReportId == reportId);
         if (report != null)
         {
             context.Reports.Remove(report);
             context.SaveChanges();
         }
     }
 }
 public DbExpenseReport SaveExpenseReport(DbExpenseReport report)
 {
     using (var context = new ExpensesContext())
     {
         if (report.ExpenseReportId != 0)
         {
             context.Reports.Attach(report);
             context.Entry <DbExpenseReport>(report).State = System.Data.Entity.EntityState.Modified;
         }
         else
         {
             context.Reports.Add(report);
         }
         context.SaveChanges();
         return(report);
     }
 }
        public DbEmployee SaveEmployee(DbEmployee employee)
        {
            using (var context = new ExpensesContext())
            {
                if (employee.EmployeeId != 0)
                {
                    context.Employees.Attach(employee);
                    context.Entry <DbEmployee>(employee).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    context.Employees.Add(employee);
                }

                context.SaveChanges();
                return(employee);
            }
        }
Пример #10
0
        public DbCharge SaveCharge(DbCharge charge)
        {
            using (var context = new ExpensesContext())
            {
                if (charge.ChargeId != 0)
                {
                    context.Charges.Attach(charge);
                    context.Entry <DbCharge>(charge).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    context.Charges.Add(charge);
                }

                context.SaveChanges();
                return(charge);
            }
        }
        public DbCharge SaveCharge(DbCharge charge)
        {
            using (var context = new ExpensesContext())
            {
                if (charge.ChargeId != 0)
                {
                    context.Charges.Attach(charge);
                    context.Entry<DbCharge>(charge).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    context.Charges.Add(charge);
                }

                context.SaveChanges();
                return charge;
            }
        }
 public DbExpenseReport SaveExpenseReport(DbExpenseReport report)
 {
     using (var context = new ExpensesContext())
     {
         if (report.ExpenseReportId != 0)
         {
             context.Reports.Attach(report);
             context.Entry<DbExpenseReport>(report).State = System.Data.Entity.EntityState.Modified;
         }
         else
         {
             context.Reports.Add(report);
         }
         context.SaveChanges();
         return report;
     }
 }
        public DbEmployee SaveEmployee(DbEmployee employee)
        {
            using (var context = new ExpensesContext())
            {
                if (employee.EmployeeId != 0)
                {
                    context.Employees.Attach(employee);
                    context.Entry<DbEmployee>(employee).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    context.Employees.Add(employee);
                }

                context.SaveChanges();
                return employee;
            }
        }