public async Task <int> AddPetImageAsync(Guid petCode, PetImageTableModel petImageTable) { petImageTable.Code = Guid.NewGuid(); petImageTable.CreatedOn = DateTime.Now; long imagePetId; using (var dbConnection = _dbConnectionFactory.Open()) { using (var trans = dbConnection.OpenTransaction(IsolationLevel.ReadCommitted)) { var pet = await dbConnection.SingleAsync <PetTableModel>(x => x.Code == petCode) .ConfigureAwait(false); petImageTable.PetTableModelId = pet.Id; if (petImageTable.IsProfileImage) { await dbConnection.UpdateOnlyAsync(new PetImageTableModel { IsProfileImage = false }, x => x.IsProfileImage, x => x.PetTableModelId == pet.Id) .ConfigureAwait(false); } imagePetId = await dbConnection.InsertAsync <PetImageTableModel>(petImageTable, selectIdentity : true) .ConfigureAwait(false); trans.Commit(); } } return((int)imagePetId); }
public async Task <int> AddPetImageAsync(int petId, PetImageTableModel petImageTable) { petImageTable.PetTableModelId = petId; petImageTable.Code = Guid.NewGuid(); petImageTable.CreatedOn = DateTime.Now; return(await _petImageBaseDataAccess.AddAsync(petImageTable) .ConfigureAwait(false)); }
public PetImage MapPetImageTableToPetImage(PetImageTableModel petImageTable) { return(new PetImage { Id = petImageTable.Id, Code = petImageTable.Code, ImageUrl = petImageTable.ImageUrl, IsProfileImage = petImageTable.IsProfileImage }); }