public RegisteredAnimal MarkAs(string userId, Guid rAnimalId, Status status, string title, string description, Coordinate coordinates)
        {
            if (status.Equals(Status.Found))
            {
                var foundRAnimal = _registeredAnimalProvider.Get(rAnimalId);
                if (foundRAnimal == null)
                {
                    throw new ApiException(HttpStatusCode.Forbidden, ApiError.NotFound);
                }
                if (!foundRAnimal.UserId.Equals(userId))
                {
                    throw new ApiException(HttpStatusCode.Forbidden, ApiError.AccessForbidden);
                }

                //remove from animal list
                _animalDataProvider.Remove(foundRAnimal.Animal);

                //remove link
                foundRAnimal.Animal = null;
                _registeredAnimalProvider.Update(foundRAnimal);

                _unitOfWork.Commit();

                return(RegisteredAnimalMapper.DtoS(foundRAnimal));
            }

            var lostRAnimal = _registeredAnimalProvider.Get(rAnimalId);

            if (lostRAnimal == null)
            {
                throw new ApiException(HttpStatusCode.Forbidden, ApiError.NotFound);
            }
            if (!lostRAnimal.UserId.Equals(userId))
            {
                throw new ApiException(HttpStatusCode.Forbidden, ApiError.AccessForbidden);
            }

            var animal = new DAL.Entity.Animal()
            {
                Image       = lostRAnimal.Image,
                Title       = string.IsNullOrEmpty(title) ? lostRAnimal.Name : title,
                Description = string.IsNullOrEmpty(description) ? "" : description,
                UploadDate  = DateTimeOffset.Now,
                Status      = Status.Lost,
                Coordinates = new List <DAL.Entity.Coordinate>()
                {
                    CoordinateMapper.StoD(coordinates)
                }
            };

            lostRAnimal.Animal = animal;

            var updatedAnimal = _registeredAnimalProvider.Update(lostRAnimal);

            _unitOfWork.Commit();

            return(RegisteredAnimalMapper.DtoS(updatedAnimal));
        }
Ejemplo n.º 2
0
        public Guid Remove(string userId, Guid id)
        {
            var animal = _animalDataProvider.Get(id);

            if (animal == null)
            {
                throw new ApiException(HttpStatusCode.Forbidden, ApiError.NotFound);
            }
            if (!animal.UserId.Equals(userId))
            {
                throw new ApiException(HttpStatusCode.Forbidden, ApiError.AccessForbidden);
            }

            var returnedId = _animalDataProvider.Remove(animal);

            _unitOfWork.Commit();

            return(returnedId);
        }