public async Task <int> SaveTaskAsync(TaskModel model) { TaskEntity taskEntity = await _taskRep.FirstOrDefaultWithDeletedAsync(m => m.Id == model.Id); using (Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction trs = await _uow.BeginTransactionAsync()) { if (taskEntity == null) { //yeni kayit taskEntity = Mapper.Map <TaskModel, TaskEntity>(model); await _taskRep.AddAsync(taskEntity); await _uow.SaveChangesAsync(); trs.Commit(); } else { //güncelleme Mapper.Map(model, taskEntity); taskEntity.IsDeleted = false; await _taskRep.UpdateAsync(taskEntity); await _uow.SaveChangesAsync(); trs.Commit(); } } return(taskEntity.Id); }
public async Task <int> SaveAddressAsync(AddressModel model) { AddressEntity addressEntity = await _addressRep.FirstOrDefaultAsync(m => m.Id == model.Id); using (Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction trs = await _uow.BeginTransactionAsync()) { if (addressEntity == null) { //yeni kayit addressEntity = Mapper.Map <AddressModel, AddressEntity>(model); await _addressRep.AddAsync(addressEntity); await _uow.SaveChangesAsync(); } else { //güncelleme Mapper.Map(model, addressEntity); await _addressRep.UpdateAsync(addressEntity); await _uow.SaveChangesAsync(); } trs.Commit(); } return(addressEntity.Id); }