Exemplo n.º 1
0
        public async Task <int> ManageAdminFoundAlertsAsync(AdminManageFoundAlertRequest request)
        {
            int records;
            PetAlertTableModel petAlert = null;

            using (var dbConnection = _dbConnectionFactory.Open())
            {
                using (var trans = dbConnection.OpenTransaction())
                {
                    if (request.Id.HasValue)
                    {
                        petAlert = await dbConnection.SingleByIdAsync <PetAlertTableModel>(request.Id.Value)
                                   .ConfigureAwait(false);
                    }
                    else if (request.Code.HasValue)
                    {
                        petAlert = await dbConnection.SingleAsync <PetAlertTableModel>(p => p.Code == request.Code.Value)
                                   .ConfigureAwait(false);
                    }

                    var action = request.Action;

                    records = await dbConnection.UpdateOnlyAsync(new PetAlertTableModel { Approved = action }, x => x.Approved, x => x.Id == petAlert.Id)
                              .ConfigureAwait(false);

                    trans.Commit();
                }
            }

            return(records);
        }
Exemplo n.º 2
0
        public async Task <PetAlertTableModel> GetPetAlertByCodeAsync(Guid petAlertCode)
        {
            var petAlert = new PetAlertTableModel();

            using (var dbConnection = _dbConnectionFactory.Open())
            {
                petAlert = await dbConnection.SingleAsync <PetAlertTableModel>(p => p.Code == petAlertCode)
                           .ConfigureAwait(false);

                await dbConnection.LoadReferencesAsync(petAlert);
            }

            return(petAlert);
        }
Exemplo n.º 3
0
 public PetAlert MapPetAlertTableToPetAlert(PetAlertTableModel petAlertTable)
 {
     return(new PetAlert
     {
         Id = petAlertTable.Id,
         Code = petAlertTable.Code,
         PetId = petAlertTable.PetId,
         Latitude = petAlertTable.Latitude,
         Longitude = petAlertTable.Longitude,
         Type = petAlertTable.AlertType,
         Status = petAlertTable.AlertStatus,
         CreatedOn = petAlertTable.CreatedOn,
         SolvedOn = petAlertTable.SolvedOn
     });
 }
Exemplo n.º 4
0
        public async Task <int> AddPetAlertAsync(PetAlertTableModel petAlertTable)
        {
            long newId;

            using (var dbConnection = _dbConnectionFactory.Open())
            {
                using (var trans = dbConnection.OpenTransaction())
                {
                    var pet = await dbConnection.SingleAsync <PetTableModel>(p => p.Id == petAlertTable.PetId)
                              .ConfigureAwait(false);

                    newId = await dbConnection.InsertAsync <PetAlertTableModel>(petAlertTable, selectIdentity : true)
                            .ConfigureAwait(false);

                    await dbConnection.UpdateOnlyAsync(new PetTableModel { Status = (int)PetStatusEnum.Lost }, x => x.Status, x => x.Id == pet.Id)
                    .ConfigureAwait(false);

                    trans.Commit();
                }
            }

            return((int)newId);
        }
Exemplo n.º 5
0
        public async Task <int> AddPetPublicAlertAsync(PetAlertTableModel petAlertTable, List <PetAlertImageTableModel> petAlertImagesTable)
        {
            long newId;

            using (var dbConnection = _dbConnectionFactory.Open())
            {
                using (var trans = dbConnection.OpenTransaction())
                {
                    newId = await dbConnection.InsertAsync <PetAlertTableModel>(petAlertTable, selectIdentity : true)
                            .ConfigureAwait(false);

                    foreach (var image in petAlertImagesTable)
                    {
                        image.PetAlertTableModelId = (int)newId;
                        await dbConnection.InsertAsync <PetAlertImageTableModel>(image)
                        .ConfigureAwait(false);
                    }

                    trans.Commit();
                }
            }

            return((int)newId);
        }
Exemplo n.º 6
0
        public async Task <PetAlertDetails> GetPetAlertDetailsAsync(PetAlertDetailsRequest request)
        {
            PetAlertDetails    petAlertDetails = null;
            PetAlertTableModel petAlertTable   = null;

            using (var dbConnection = _dbConnectionFactory.Open())
            {
                petAlertTable = await dbConnection.SingleAsync <PetAlertTableModel>(pa => pa.Code == request.AlertCode &&
                                                                                    pa.AlertStatus == (int)AlertStatusEnum.Active)
                                .ConfigureAwait(false);

                if (petAlertTable != null)
                {
                    petAlertDetails            = new PetAlertDetails();
                    petAlertDetails.PetInfo    = new PetDetails();
                    petAlertDetails.OwnersInfo = new List <OwnerDetails>();
                    OwnerDetails ownerDetails;

                    // --- Pet Details ---
                    if (petAlertTable.PetId.HasValue && petAlertTable.PetId > 0)
                    {
                        var petQuery = dbConnection.From <PetTableModel>()
                                       .Join <PetTableModel, PetAlertTableModel>((p, pa) => p.Id == pa.PetId &&
                                                                                 pa.Code == petAlertTable.Code);

                        var petResult = await dbConnection.SelectMultiAsync <PetTableModel, PetAlertTableModel>(petQuery)
                                        .ConfigureAwait(false);

                        var petImages = await dbConnection.SelectAsync <PetImageTableModel>(pi => pi.PetTableModelId == petAlertTable.PetId.Value)
                                        .ConfigureAwait(false);

                        foreach (var item in petResult)
                        {
                            petAlertDetails.PetInfo.Name             = item.Item1.Name;
                            petAlertDetails.PetInfo.ProfileImageUrl  = petImages.Where(pi => pi.IsProfileImage).FirstOrDefault()?.ImageUrl;
                            petAlertDetails.PetInfo.DateOfBirth      = item.Item1.DateOfBirth;
                            petAlertDetails.PetInfo.Description      = item.Item1.Description;
                            petAlertDetails.PetInfo.LostComment      = item.Item2.Comment;
                            petAlertDetails.PetInfo.LostDateTime     = item.Item2.CreatedOn;
                            petAlertDetails.PetInfo.PositionImageUrl = item.Item2.PositionImageUrl;
                            petAlertDetails.PetInfo.Images           = petImages.Select(pi => pi.ImageUrl).ToList();
                        }
                    }
                    else
                    {
                        var petImages = await dbConnection.SelectAsync <PetAlertImageTableModel>(pi => pi.PetAlertTableModelId == petAlertTable.Id)
                                        .ConfigureAwait(false);

                        petAlertDetails.PetInfo.Name             = GeneralHelper.GetAnonymousTitle(petAlertTable.AlertType);
                        petAlertDetails.PetInfo.LostComment      = petAlertTable.Comment;
                        petAlertDetails.PetInfo.LostDateTime     = petAlertTable.CreatedOn;
                        petAlertDetails.PetInfo.PositionImageUrl = petAlertTable.PositionImageUrl;
                        petAlertDetails.PetInfo.Images           = petImages.Select(x => x.ImageUrl).ToList();
                    }

                    // --- Owner Details ---
                    if (petAlertTable.OwnerTableModelId.HasValue && petAlertTable.OwnerTableModelId > 0)
                    {
                        // --- Owner's Pet --
                        if (petAlertTable.PetId.HasValue && petAlertTable.PetId.Value > 0)
                        {
                            var ownersQuery = dbConnection.From <OwnerPetTableModel>()
                                              .Join <OwnerPetTableModel, OwnerTableModel>((op, o) => op.OwnerTableModelId == o.Id)
                                              .Join <OwnerPetTableModel, OwnerSettingTableModel>((op, os) => op.OwnerTableModelId == os.OwnerTableModelId)
                                              .Where(op => op.PetTableModelId == petAlertTable.PetId.Value);

                            var ownersResult = await dbConnection.SelectMultiAsync <OwnerPetTableModel, OwnerTableModel, OwnerSettingTableModel>(ownersQuery)
                                               .ConfigureAwait(false);

                            foreach (var item in ownersResult)
                            {
                                ownerDetails = new OwnerDetails
                                {
                                    FullName        = $"{item.Item2.FirstName} {item.Item2.LastName}",
                                    ProfileImageUrl = item.Item2.ProfileImageUrl,
                                    Email           = item.Item3.ShowEmailForAlerts ? item.Item2.Email : string.Empty,
                                    PhoneNumber1    = item.Item3.ShowPhoneNumberForAlerts ? item.Item2.PhoneNumber1 : string.Empty,
                                    PhoneNumber2    = item.Item3.ShowPhoneNumberForAlerts ? item.Item2.PhoneNumber2 : string.Empty,
                                    Address1        = item.Item3.ShowAddressForAlerts ? item.Item2.Address1 : string.Empty,
                                    Address2        = item.Item3.ShowAddressForAlerts ? item.Item2.Address2 : string.Empty
                                };

                                petAlertDetails.OwnersInfo.Add(ownerDetails);
                            }
                        }
                        else // --- Other Pet ---
                        {
                            var ownersQuery = dbConnection.From <OwnerTableModel>()
                                              .Join <OwnerTableModel, OwnerSettingTableModel>((o, os) => o.Id == os.OwnerTableModelId)
                                              .Where(o => o.Id == petAlertTable.OwnerTableModelId);

                            var ownersResult = await dbConnection.SelectMultiAsync <OwnerTableModel, OwnerSettingTableModel>(ownersQuery)
                                               .ConfigureAwait(false);

                            foreach (var item in ownersResult)
                            {
                                ownerDetails = new OwnerDetails
                                {
                                    FullName        = $"{item.Item1.FirstName} {item.Item1.LastName}",
                                    ProfileImageUrl = item.Item1.ProfileImageUrl,
                                    Email           = item.Item2.ShowEmailForAlerts ? item.Item1.Email : string.Empty,
                                    PhoneNumber1    = item.Item2.ShowPhoneNumberForAlerts ? item.Item1.PhoneNumber1 : string.Empty,
                                    PhoneNumber2    = item.Item2.ShowPhoneNumberForAlerts ? item.Item1.PhoneNumber2 : string.Empty,
                                    Address1        = item.Item2.ShowAddressForAlerts ? item.Item1.Address1 : string.Empty,
                                    Address2        = item.Item2.ShowAddressForAlerts ? item.Item1.Address2 : string.Empty
                                };

                                petAlertDetails.OwnersInfo.Add(ownerDetails);
                            }
                        }
                    }
                }
            }

            return(petAlertDetails);
        }