示例#1
0
        public static List <PetData> GetUserPets(int userId)
        {
            PetRepository   petRep   = new PetRepository();
            KindRepository  kindRep  = new KindRepository();
            BreedRepository breedRep = new BreedRepository();

            List <PhotoData> photos = GetPhotos();

            List <PetData> pets = new List <PetData>();

            petRep.GetUserPets(userId).ToList().ForEach(x => pets.Add(new PetData
            {
                Id           = x.Id,
                Nickname     = x.Nickname,
                KindId       = x.KindId,
                BreedId      = x.BreedId,
                Kind         = kindRep.Get(x.KindId).Name,
                Breed        = breedRep.Get(x.BreedId).Name,
                Conditions   = x.Conditions,
                ArrivalDate  = x.ArrivalDate,
                Color        = x.Color,
                HealthStatus = x.HealthStatus,
                Photos       = photos.Where(k => k.PetId == x.Id).ToList()
            }));
            return(pets);
        }
示例#2
0
 public IHttpActionResult Get()
 {
     return(Ok(_br.Get()));
 }
示例#3
0
        public static List <PetData> GetPets()
        {
            PetRepository       petRep      = new PetRepository();
            KindRepository      kindRep     = new KindRepository();
            BreedRepository     breedRep    = new BreedRepository();
            UserRepository      userRep     = new UserRepository();
            UserTypeRepository  userTypeRep = new UserTypeRepository();
            OperationRepository operRep     = new OperationRepository();

            List <PhotoData> photos = GetPhotos();

            List <PetData> pets = new List <PetData>();

            petRep.GetAll().ToList().ForEach(x => pets.Add(new PetData
            {
                Id           = x.Id,
                Nickname     = x.Nickname,
                KindId       = x.KindId,
                BreedId      = x.BreedId,
                Kind         = kindRep.Get(x.KindId).Name,
                Breed        = breedRep.Get(x.BreedId).Name,
                Conditions   = x.Conditions,
                ArrivalDate  = x.ArrivalDate,
                Color        = x.Color,
                HealthStatus = x.HealthStatus,
                Photos       = photos.Where(k => k.PetId == x.Id).ToList()
            }));

            List <OperationData> op = new List <OperationData>(operRep.GetAll().ToList().Select(x => new OperationData
            {
                Id            = x.Id,
                PetId         = x.PetId,
                OperationDate = x.OperationDate,
                UserId        = x.UserId
            }));

            List <UserData> users = new List <UserData>();

            userRep.GetAll().ToList().ForEach(x => users.Add(new UserData
            {
                Id       = x.Id,
                Username = x.Username,
                Password = x.Password,
                UserType = new UserTypeData
                {
                    Id   = userTypeRep.Get(x.UserTypeId).Id,
                    Name = userTypeRep.Get(x.UserTypeId).Name
                },
                UserTypeId  = x.UserTypeId,
                FullName    = x.FullName,
                Address     = x.Address,
                PhoneNumber = x.PhoneNumber
            }));

            op.ForEach(x =>
                       pets.Where(p => p.Id == x.PetId).ToList()
                       .ForEach(pp => pp.User = users.FirstOrDefault(u => u.Id == x.UserId)));


            return(pets);
        }