/// <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); } }
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")); }
/// <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); } }
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); }
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); } }
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); } }
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)); }
/// <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) )); }
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); } }
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); } }
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); }
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")); }
public bool HasPet(PetId petId) => _pets.Any(p => p.PetId.Equals(petId));
public override int GetHashCode() { return(GetType().GetHashCode() * 907 + PetId.GetHashCode() + ResponsibleId.GetHashCode()); }
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"); }
public override string ToString() { return(GetType().Name + " [Id=" + PetId.GetHashCode() + ResponsibleId.GetHashCode() + "]"); }
public Task <Exception> DeletePetAsync(Person person, PetId petId) { var error = person.DeletePet(petId); return(Task.FromResult(error)); }