示例#1
0
        public int DeletePet(string code)
        {
            var request = new PetDeleteRequest {
                Code = Guid.Parse(code)
            };

            return(_petServiceClient.DeletePet(request));
        }
示例#2
0
        public async Task <int> Delete(PetDeleteRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(await _petProvider.DeletePetAsync(request)
                   .ConfigureAwait(false));
        }
示例#3
0
        public PetWhizzResponse DeletePet(PetDeleteRequest PetDeleteRequest)
        {
            PetWhizzResponse _oResponse;

            try
            {
                animalService.DeletePet(PetDeleteRequest);
                _oResponse = Utils.CreateSuccessResponse(null);
            }
            catch (Exception ex)
            {
                _oResponse = Utils.CreateErrorResponse(ex);
            }
            return(_oResponse);
        }
示例#4
0
        public async Task <int> DeletePetAsync(PetDeleteRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (!request.Id.HasValue && !request.Code.HasValue)
            {
                throw new ArgumentException("Id and Code are NULL");
            }

            int records = await _petDataAccess.DeletePetAsync(request)
                          .ConfigureAwait(false);

            return(records);
        }
示例#5
0
        public async Task <int> DeletePetAsync(PetDeleteRequest request)
        {
            var records = 0;

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

                    // Delete Alerts
                    await dbConnection.DeleteAsync <PetAlertTableModel>(x => x.PetId == pet.Id)
                    .ConfigureAwait(false);

                    // Delete Images
                    await dbConnection.DeleteAsync <PetImageTableModel>(x => x.PetTableModelId == pet.Id)
                    .ConfigureAwait(false);

                    // Delete asociated owners records
                    await dbConnection.DeleteAsync <OwnerPetTableModel>(x => x.PetTableModelId == pet.Id)
                    .ConfigureAwait(false);

                    // Delete shared owners requests
                    await dbConnection.DeleteAsync <OwnerSharedPetTableModel>(x => x.PetTableModelId == pet.Id)
                    .ConfigureAwait(false);

                    // Delete Pet
                    records = await dbConnection.DeleteByIdAsync <PetTableModel>(pet.Id)
                              .ConfigureAwait(false);

                    trans.Commit();
                }
            }

            return(records);
        }
示例#6
0
 internal void DeletePet(PetDeleteRequest petDeleteRequest)
 {
     logger.Trace("Recived get pets delete request");
     try
     {
         CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;
         petDeleteRequest.petId = Decryptor.Decrypt(petDeleteRequest.petId).Split('|')[1];
         Int64 petId = Convert.ToInt64(petDeleteRequest.petId);
         if (String.IsNullOrEmpty(petDeleteRequest.petId))
         {
             logger.Error("Pet id not found on request");
             throw new CustomException("Pet id not found on request", (int)ErrorCode.VALIDATIONFAILED);
         }
         using (var ctx = new PetWhizzEntities())
         {
             pet Pet = ctx.pets.Where(a => a.id == petId).FirstOrDefault();
             if (Pet.petOwners.Where(a => a.userId == currentUser.userId && a.isActive == true && a.isMainOwner == true).FirstOrDefault() == null)
             {
                 logger.Error("Requested user not belongs to the pet or not the main owner");
                 throw new CustomException("Requested user not belongs to the pet or not the main owner", (int)ErrorCode.UNAUTHORIZED);
             }
             //delete pet
             ctx.pets.Attach(Pet);
             Pet.isActive  = false;
             Pet.isDeleted = true;
             ctx.SaveChanges();
             logger.Trace("Pet successfully deleted");
         }
     }
     catch (CustomException) { throw; }
     catch (Exception ex)
     {
         logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
         throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
     }
 }
示例#7
0
        public int DeletePet(PetDeleteRequest request)
        {
            var response = _findMyPetClient.JsonClient().Delete(request);

            return(response);
        }