コード例 #1
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (PetId != null)
         {
             hashCode = hashCode * 59 + PetId.GetHashCode();
         }
         if (Quantity != null)
         {
             hashCode = hashCode * 59 + Quantity.GetHashCode();
         }
         if (ShipDate != null)
         {
             hashCode = hashCode * 59 + ShipDate.GetHashCode();
         }
         if (Status != null)
         {
             hashCode = hashCode * 59 + Status.GetHashCode();
         }
         if (Complete != null)
         {
             hashCode = hashCode * 59 + Complete.GetHashCode();
         }
         return(hashCode);
     }
 }
コード例 #2
0
        public async Task <ApplicationResponse <PetState> > UpdatePetAsync(string personId, PetState updatedPet)
        {
            // demonstrate updating an entity through the aggregate root that is not the root itself

            var personState = await _personRepository.GetAsync(personId);

            if (personState == null)
            {
                return(new ApplicationResponse <PetState>(false, ResponseType.EntityNotFound, $"Could not find person {personId}"));
            }

            var person = _mapper.Map <Person>(personState);

            var ptId = new PetId(updatedPet.PetId);

            if (!person.HasPet(ptId))
            {
                return(new ApplicationResponse <PetState>(false, ResponseType.EntityNotFound, $"The customer does not own this pet."));
            }

            var replacementPet = _mapper.Map <Pet>(updatedPet);
            var updateError    = person.UpdatePet(replacementPet);

            if (updateError != null)
            {
                return(new ApplicationResponse <PetState>(false, ResponseType.BusinessRuleViolation, updateError.Message));
            }

            await _personRepository.SavePersonAsync(person);

            return(new ApplicationResponse <PetState>(true, ResponseType.Success, updatedPet, "ok"));
        }
コード例 #3
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     // credit: http://stackoverflow.com/a/263416/677735
     unchecked // Overflow is fine, just wrap
     {
         var hash = 41;
         // Suitable nullity checks etc, of course :)
         if (Id != null)
         {
             hash = hash * 59 + Id.GetHashCode();
         }
         if (PetId != null)
         {
             hash = hash * 59 + PetId.GetHashCode();
         }
         if (Quantity != null)
         {
             hash = hash * 59 + Quantity.GetHashCode();
         }
         if (ShipDate != null)
         {
             hash = hash * 59 + ShipDate.GetHashCode();
         }
         if (Status != null)
         {
             hash = hash * 59 + Status.GetHashCode();
         }
         if (Complete != null)
         {
             hash = hash * 59 + Complete.GetHashCode();
         }
         return(hash);
     }
 }
コード例 #4
0
        public Exception DeletePet(PetId petId)
        {
            if (!_pets.Any(p => p.PetId.Equals(petId)))
            {
                return(new InvalidOperationException("Cannot delete a pet that does not exist."));
            }

            _pets.RemoveAll(p => p.PetId.Equals(petId));
            return(null);
        }
コード例 #5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = PetId.GetHashCode();
         hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ SpeciesId.GetHashCode();
         hashCode = (hashCode * 397) ^ IsActive.GetHashCode();
         return(hashCode);
     }
 }
コード例 #6
0
    public void Create(Guid id, string name, DateTime dateOfBirth)
    {
        var pet = new Pet(PetId.Create(id));

        pet.SetName(PetName.Create(name));
        pet.SetDateOfBirth(PetDateOfBirth.Create(dateOfBirth));
        _pets.Add(pet);

        foreach (var domainEvent in pet.DomainEvents)
        {
            _messageBroker.Publish(domainEvent);
        }
    }
コード例 #7
0
        public override bool Equals(object obj)
        {
            var compareTo = obj as Adoption;

            if (ReferenceEquals(this, compareTo))
            {
                return(true);
            }
            if (ReferenceEquals(null, compareTo))
            {
                return(false);
            }

            return(PetId.Equals(compareTo.PetId) && ResponsibleId.Equals(compareTo.ResponsibleId));
        }
コード例 #8
0
ファイル: Order.cs プロジェクト: zippolyte/openapi-generator
        /// <summary>
        /// Returns true if Order instances are equal
        /// </summary>
        /// <param name="other">Instance of Order to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Order other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||

                     Id.Equals(other.Id)
                     ) &&
                 (
                     PetId == other.PetId ||

                     PetId.Equals(other.PetId)
                 ) &&
                 (
                     Quantity == other.Quantity ||

                     Quantity.Equals(other.Quantity)
                 ) &&
                 (
                     ShipDate == other.ShipDate ||
                     ShipDate != null &&
                     ShipDate.Equals(other.ShipDate)
                 ) &&
                 (
                     Status == other.Status ||

                     Status.Equals(other.Status)
                 ) &&
                 (
                     Complete == other.Complete ||

                     Complete.Equals(other.Complete)
                 ));
        }
コード例 #9
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = nameof(UploadFileRequest).GetHashCode();
         if (default != PetId)
         {
             hashCode = (hashCode * 397) ^ PetId.GetHashCode();
         }
         if (default != AdditionalMetadata)
         {
             hashCode = (hashCode * 397) ^ AdditionalMetadata.GetHashCode();
         }
         if (default != File)
         {
             hashCode = (hashCode * 397) ^ File.GetHashCode();
         }
         return(hashCode);
     }
 }
コード例 #10
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = nameof(UpdatePetWithFormRequest).GetHashCode();
         if (default != PetId)
         {
             hashCode = (hashCode * 397) ^ PetId.GetHashCode();
         }
         if (default != Name)
         {
             hashCode = (hashCode * 397) ^ Name.GetHashCode();
         }
         if (default != Status)
         {
             hashCode = (hashCode * 397) ^ Status.GetHashCode();
         }
         return(hashCode);
     }
 }
コード例 #11
0
ファイル: Hero.cs プロジェクト: liligege/wz_game
        public override int GetHashCode()
        {
            int hash = 1;

            if (HeroId != 0L)
            {
                hash ^= HeroId.GetHashCode();
            }
            hash ^= equip_.GetHashCode();
            if (PetId != 0L)
            {
                hash ^= PetId.GetHashCode();
            }
            if (HorseId != 0L)
            {
                hash ^= HorseId.GetHashCode();
            }
            if (MingjiangId != 0L)
            {
                hash ^= MingjiangId.GetHashCode();
            }
            return(hash);
        }
コード例 #12
0
        public async Task <ApplicationResponse <PetState> > DeletePetAsync(string personId, string petId)
        {
            var personState = await _personRepository.GetAsync(personId);

            if (personState == null)
            {
                return(new ApplicationResponse <PetState>(false, ResponseType.EntityNotFound, $"Could not find person {personId}"));
            }

            var person = _mapper.Map <Person>(personState);

            var ptId = new PetId(petId);

            if (!person.HasPet(ptId))
            {
                return(new ApplicationResponse <PetState>(false, ResponseType.EntityNotFound, $"The customer does not own this pet or it is already inactive."));
            }

            await _domainService.DeletePetAsync(person, ptId);

            await _personRepository.SavePersonAsync(person);

            return(new ApplicationResponse <PetState>(true, ResponseType.Success, "ok"));
        }
コード例 #13
0
 public bool HasPet(PetId petId) => _pets.Any(p => p.PetId.Equals(petId));
コード例 #14
0
 public override int GetHashCode()
 {
     return(GetType().GetHashCode() * 907 + PetId.GetHashCode() + ResponsibleId.GetHashCode());
 }
コード例 #15
0
 public override string ToString()
 {
     return($"ID = {PetId.ToString()}, Name = {Name.ToString()}, Type = {PetType.ToString()}, BirthDate = {BirthDate.ToString()}, SoldDate = {SoldDate.ToString()}, PreviousOwner = {Owner.ToString()}, Price = {Price.ToString()},\n");
 }
コード例 #16
0
 public override string ToString()
 {
     return(GetType().Name + " [Id=" + PetId.GetHashCode() + ResponsibleId.GetHashCode() + "]");
 }
コード例 #17
0
        public Task <Exception> DeletePetAsync(Person person, PetId petId)
        {
            var error = person.DeletePet(petId);

            return(Task.FromResult(error));
        }