public async Task <List <AccountDto> > All() { using (SpendingsDBContext context = new SpendingsDBContext()) { List <Account> accountsToMap = await context.Accounts.ToListAsync(); return(Mapper.Map <List <Account>, List <AccountDto> >(accountsToMap)); } }
public async Task <List <OperationTypeDto> > All() { using (SpendingsDBContext context = new SpendingsDBContext()) { List <OperationType> fromDb = await context.OperationTypes.ToListAsync(); return(Mapper.Map <List <OperationType>, List <OperationTypeDto> >(fromDb)); } }
public async Task Update(OperationTypeDto t) { using (SpendingsDBContext context = new SpendingsDBContext()) { OperationType toUpdate = Mapper.Map <OperationTypeDto, OperationType>(t); context.OperationTypes.Attach(toUpdate); context.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified; await context.SaveChangesAsync(); } }
public async Task <int> Add(OperationTypeDto item) { using (SpendingsDBContext context = new SpendingsDBContext()) { OperationType toAdd = Mapper.Map <OperationTypeDto, OperationType>(item); context.OperationTypes.Add(toAdd); await context.SaveChangesAsync(); return(toAdd.Id); } }
public async Task <int> Add(AccountDto toMap) { using (SpendingsDBContext context = new SpendingsDBContext()) { Account toAdd = Mapper.Map <AccountDto, Account>(toMap); context.Accounts.Add(toAdd); await context.SaveChangesAsync(); return(toAdd.Id); } }
public async Task <OperationTypeDto> Get(int i) { using (SpendingsDBContext context = new SpendingsDBContext()) { OperationType toGet = await context.OperationTypes.FirstOrDefaultAsync(d => d.Id == i); if (toGet == null) { return(null); } return(Mapper.Map <OperationType, OperationTypeDto>(toGet)); } }
public async Task <AccountDto> Get(int i) { using (SpendingsDBContext context = new SpendingsDBContext()) { Account fromDb = await context.Accounts.FirstOrDefaultAsync(d => d.Id == i); if (fromDb == null) { return(null); } return(Mapper.Map <Account, AccountDto>(fromDb)); } }
public async Task <List <AccountDto> > Filter(AccountDtoFilter filter) { using (SpendingsDBContext context = new SpendingsDBContext()) { List <Account> fromDb = new List <Account>(); if (filter.IdCurrency != null) { fromDb = await context.Accounts.Where(d => d.IdCurrency == filter.IdCurrency).ToListAsync(); } return(Mapper.Map <List <Account>, List <AccountDto> >(fromDb)); } }
public async Task <OperationDto> Get(int i) { using (SpendingsDBContext context = new SpendingsDBContext()) { Operation fromDb = await context.Operations.FirstOrDefaultAsync(d => d.Id == i); if (fromDb == null) { return(null); } return(Mapper.Map <Operation, OperationDto>(fromDb)); } }
public async Task Update(AccountDto t) { using (SpendingsDBContext context = new SpendingsDBContext()) { //Account toUpdate = context.Accounts.FirstOrDefault(d => d.Id == t.Id); //toUpdate.Name = t.Name; //toUpdate.IdCurrency = t.IdCurrency; Account toUpdate = Mapper.Map <AccountDto, Account>(t); context.Accounts.Attach(toUpdate); context.Entry(toUpdate).State = System.Data.Entity.EntityState.Modified; await context.SaveChangesAsync(); } }
public async Task <bool> Delete(int id) { using (SpendingsDBContext context = new SpendingsDBContext()) { OperationType toDelete = await context.OperationTypes.FirstOrDefaultAsync(d => d.Id == id); if (toDelete == null) { return(false); } context.OperationTypes.Remove(toDelete); await context.SaveChangesAsync(); return(true); } }
public async Task <List <OperationDto> > Filter(OperationDtoFilter filter) { using (SpendingsDBContext context = new SpendingsDBContext()) { IQueryable <Operation> query = context.Operations; if (filter.IdAccount != null) { query = query.Where(d => d.IdAccount == filter.IdAccount); } if (filter.IdCurrency != null) { query = query.Where(d => d.Account.IdCurrency == filter.IdCurrency); } if (filter.IdOperationType != null) { query = query.Where(d => d.IdOperationType == filter.IdOperationType); } if (filter.AmmountFrom != null) { query = query.Where(d => d.Ammount >= filter.AmmountFrom); } if (filter.AmmountTo != null) { query = query.Where(d => d.Ammount <= filter.AmmountTo); } if (filter.DateFrom != null) { query = query.Where(d => d.Date >= filter.DateFrom); } if (filter.DateTo != null) { query = query.Where(d => d.Date <= filter.DateTo); } return(Mapper.Map <List <Operation>, List <OperationDto> >(await query.ToListAsync())); } }