public DTO.Expense CreateExpense(Expense expense) { return new DTO.Expense() { Amount = expense.Amount, Date = expense.Date, Description = expense.Description, ExpenseGroupId = expense.ExpenseGroupId, Id = expense.Id }; }
public RepositoryActionResult<Expense> UpdateExpense(Expense e) { try { // you can only update when an expense already exists for this id var existingExpense = _ctx.Expenses.FirstOrDefault(exp => exp.Id == e.Id); if (existingExpense == null) { return new RepositoryActionResult<Expense>(e, RepositoryActionStatus.NotFound); } // change the original entity status to detached; otherwise, we get an error on attach // as the entity is already in the dbSet // set original entity state to detached _ctx.Entry(existingExpense).State = EntityState.Detached; // attach & save _ctx.Expenses.Attach(e); // set the updated entity state to modified, so it gets updated. _ctx.Entry(e).State = EntityState.Modified; var result = _ctx.SaveChanges(); if (result > 0) { return new RepositoryActionResult<Expense>(e, RepositoryActionStatus.Updated); } else { return new RepositoryActionResult<Expense>(e, RepositoryActionStatus.NothingModified, null); } } catch (Exception ex) { return new RepositoryActionResult<Expense>(null, RepositoryActionStatus.Error, ex); } }
public RepositoryActionResult<Expense> InsertExpense(Expense e) { try { _ctx.Expenses.Add(e); var result = _ctx.SaveChanges(); if (result > 0) { return new RepositoryActionResult<Expense>(e, RepositoryActionStatus.Created); } else { return new RepositoryActionResult<Expense>(e, RepositoryActionStatus.NothingModified, null); } } catch (Exception ex) { return new RepositoryActionResult<Expense>(null, RepositoryActionStatus.Error, ex); } }
public object CreateDataShapedObject(Expense expense, List<string> lstOfFields) { return this.CreateDataShapedObject(CreateExpense(expense), lstOfFields); }
public object CreateDataShapedObject(Expense expense, List<string> lstOfFields) { // pass through from entity to DTO return CreateDataShapedObject(CreateExpense(expense), lstOfFields); }
public object CreateDataShapeObject(Expense expense, List<string> lstFields) { //entity to DTO return CreateDataShapeObject(CreateExpense(expense), lstFields); }
public object CreateDataShapedObject(Expense expense, List<string> fields) { return CreateDataShapedObject(CreateExpense(expense), fields); }