public Pet(string name, decimal weightInPounds, DateTime birthDate, PetGender gender, Breed breed, string color)
 {
     PetName        = name;
     WeightInPounds = weightInPounds;
     BirthDate      = birthDate;
     Gender         = gender;
     BelongsToBreed = breed;
     Colour         = color;
     Deceased       = false;
 }
Пример #2
0
        /// <summary>
        /// Изменить пол у питомца
        /// </summary>
        /// <param name="petId"></param>
        /// <param name="organisationId"></param>
        /// <param name="gender">Новый пол питомца</param>
        /// <param name="cancellationToken"></param>
        /// <exception cref="NotFoundException"></exception>
        /// <exception cref="PetNotFoundException"></exception>
        /// <returns></returns>
        public async Task SetGender(Guid petId, Guid organisationId, PetGender gender, CancellationToken cancellationToken)
        {
            var pet = await _petRepository.GetAsync(petId : petId, organisation : (Organisation)organisationId, cancellationToken : cancellationToken);

            if (pet is null)
            {
                throw new PetNotFoundException(petId, organisationId);
            }

            throw new NotImplementedException();
        }
Пример #3
0
        /// <summary>
        /// Создать питомца
        /// </summary>
        /// <param name="petId">Идентификатор питомца</param>
        /// <param name="organisationId">Идентификатор организации</param>
        /// <param name="name">Имя питомца</param>
        /// <param name="gender">Пол питомца</param>
        /// <param name="type">Тип питомца</param>
        /// <param name="petState">Статус питомца</param>
        /// <param name="afterPhotoLink">Ссылка на фотку после</param>
        /// <param name="beforePhotoLink">Ссылка на фотку До</param>
        /// <param name="mdShortBody">Краткий текст</param>
        /// <param name="mdBody">Длинный текст</param>
        /// <param name="cancellationToken">Токен признака отмены запроса</param>
        /// <exception cref="PetAlreadyExistsException"></exception>
        /// <exception cref="IdempotencyCheckException"></exception>
        /// <returns></returns>
        public async Task <Guid> Create(
            Guid petId,
            Guid organisationId,
            String name,
            PetGender gender,
            PetType type,
            PetState petState,
            String?afterPhotoLink,
            String?beforePhotoLink,
            String?mdShortBody,
            String?mdBody,
            CancellationToken cancellationToken)
        {
            var pet = await _petRepository.GetAsync(petId : petId, organisation : (Organisation)organisationId, cancellationToken : cancellationToken);

            // если с таким id пет уже был найден, то выполняем проверку идемпотентности
            if (pet is not null)
            {
                if (pet.Gender != gender ||
                    pet.Type != type ||
                    pet.PetState != petState ||
                    !name.Equals(pet.Name, StringComparison.InvariantCultureIgnoreCase) ||
                    (mdShortBody is not null && !mdShortBody.Equals(pet.MdShortBody, StringComparison.InvariantCultureIgnoreCase)) ||
                    (mdBody is not null && !mdBody.Equals(pet.MdBody, StringComparison.InvariantCultureIgnoreCase))
                    )
                {
                    throw new PetAlreadyExistsException(petId);
                }

                return(pet.Id);
            }

            await _petRepository.SaveAsync(
                pet : new Entity.Pet(
                    petId: petId,
                    organisation: new Organisation(organisationId),
                    name: name,
                    gender: gender,
                    type: type,
                    petState: petState,
                    afterPhotoLink: afterPhotoLink,
                    beforePhotoLink: beforePhotoLink,
                    mdShortBody: mdShortBody,
                    mdBody: mdBody,
                    createDate: _dateTimeGetter.Get(),
                    updateDate: _dateTimeGetter.Get()),
                cancellationToken : cancellationToken
                );

            return(petId);
        }
Пример #4
0
        public Pet Create(string name, int age, string ownerId, PetGender gender, int speciesId, string picture = null)
        {
            if (picture == string.Empty)
            {
                picture = "http://s.hswstatic.com/gif/animal-stereotype-orig.jpg";
            }

            var pet = new Pet
            {
                Name = name,
                Age = age,
                OwnerId = ownerId,
                Gender = gender,
                SpeciesId = speciesId,
                Picture = picture
            };

            this.pets.Add(pet);
            this.pets.Save();

            return pet;
        }
Пример #5
0
 public PetView(Guid id, String name, String?beforePhotoLink, String?afterPhotoLink, PetState petState, String mdShortBody, String?mdBody,
                PetType type, PetGender gender, DateTime updateDate)
 => (Id, Name, BeforePhotoLink, AfterPhotoLink, PetState, MdShortBody, MdBody, Type, Gender, UpdateDate)