Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
 public PetImage MapPetImageTableToPetImage(PetImageTableModel petImageTable)
 {
     return(new PetImage
     {
         Id = petImageTable.Id,
         Code = petImageTable.Code,
         ImageUrl = petImageTable.ImageUrl,
         IsProfileImage = petImageTable.IsProfileImage
     });
 }