예제 #1
0
        public void Can_Perform_Delete_On_UserTypeRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = CreateRepository(unitOfWork))
            {
                var userType = MockedUserType.CreateUserType();

                // Act
                repository.AddOrUpdate(userType);
                unitOfWork.Commit();
                var id = userType.Id;

                using (var repository2 = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax))
                {
                    repository2.Delete(userType);
                    unitOfWork.Commit();

                    var resolved = repository2.Get(id);

                    // Assert
                    Assert.That(resolved, Is.Null);
                }
            }
        }
예제 #2
0
        public string GetUserType(string username, string password)
        {
            int?id = userRep.GetUserTypeId(username, password);

            if (id != null)
            {
                return(userTypeRep.Get(id.Value).Name);
            }

            return(null);
        }
예제 #3
0
        public static UserData GetUser(int id)
        {
            UserRepository     userRep     = new UserRepository();
            UserTypeRepository userTypeRep = new UserTypeRepository();
            User     userDao = userRep.Get(id);
            UserData user    = new UserData
            {
                Id       = userDao.Id,
                Username = userDao.Username,
                Password = userDao.Password,
                UserType = new UserTypeData
                {
                    Id   = userTypeRep.Get(userDao.UserTypeId).Id,
                    Name = userTypeRep.Get(userDao.UserTypeId).Name
                },
                UserTypeId  = userDao.UserTypeId,
                FullName    = userDao.FullName,
                Address     = userDao.Address,
                PhoneNumber = userDao.PhoneNumber
            };

            return(user);
        }
예제 #4
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);
        }