예제 #1
0
        public IEnumerable <City> GetAll()
        {
            PraticalTestDbContext context = new PraticalTestDbContext();

            var obj = (from t in context.Cities
                       select t);

            return(obj.Select(a => new City()
            {
                CityId = a.CityId,
                CityName = a.CityName
            }));
        }
예제 #2
0
        public IEnumerable <Classification> GetAll()
        {
            PraticalTestDbContext context = new PraticalTestDbContext();

            var obj = (from t in context.Classifications
                       select t);

            return(obj.Select(a => new Classification()
            {
                ClassificationId = a.ClassificationId,
                ClassificationName = a.ClassificationName
            }));
        }
예제 #3
0
        public IEnumerable <User> GetAll(bool isAdmin)
        {
            PraticalTestDbContext context = new PraticalTestDbContext();

            var obj = (from t in context.Users
                       where t.IsAdmin == isAdmin
                       select t);

            return(obj.Select(a => new User()
            {
                UserId = a.UserId,
                Name = a.Name
            }));
        }
예제 #4
0
        public IEnumerable <Region> GetAll(Guid?cityId = default(Guid?))
        {
            PraticalTestDbContext context = new PraticalTestDbContext();

            var obj = (from t in context.Regions
                       where cityId.HasValue ? t.CityId == cityId.Value : 1 == 1
                       select t);

            return(obj.Select(a => new Region()
            {
                RegionId = a.RegionId,
                RegionName = a.RegionName,
                City = new City()
                {
                    CityId = a.City.CityId, CityName = a.City.CityName
                }
            }));
        }
예제 #5
0
        public User Authenticate(string userEmail)
        {
            PraticalTestDbContext context = new PraticalTestDbContext();

            var obj = (from t in context.Users
                       where t.Email == userEmail
                       select t).FirstOrDefault();

            User user = new User();

            if (obj != null)
            {
                user.UserId   = obj.UserId;
                user.Name     = obj.Name;
                user.Password = obj.Password;
                user.Email    = obj.Email;
                user.IsAdmin  = obj.IsAdmin ?? false;
            }

            return(user);
        }
예제 #6
0
        public IEnumerable <Client> GetAll(string Name, string Gender, Guid?SelectedCityGUID,
                                           Guid?SelectedRegionGUID, DateTime?LastPurchaseFrom, DateTime?LastPurchaseTo,
                                           Guid?SelectedClassificationGUID, Guid?SelectedSellerGUID)
        {
            PraticalTestDbContext context = new PraticalTestDbContext();

            var obj = (from t in context.Clients
                       select t);

            if (!string.IsNullOrEmpty(Name))
            {
                obj = obj.Where(a => a.Name == Name);
            }

            if (!string.IsNullOrEmpty(Gender))
            {
                obj = obj.Where(a => a.Gender == Gender);
            }

            if (SelectedRegionGUID.HasValue && SelectedRegionGUID.Value != Guid.Empty)
            {
                obj = obj.Where(a => a.RegionId == SelectedRegionGUID);
            }

            if (LastPurchaseFrom.HasValue && LastPurchaseFrom != DateTime.MinValue)
            {
                obj = obj.Where(a => a.LastPurchase > LastPurchaseFrom);
            }

            if (LastPurchaseTo.HasValue && LastPurchaseTo != DateTime.MinValue)
            {
                obj = obj.Where(a => a.LastPurchase < LastPurchaseTo);
            }

            if (SelectedClassificationGUID.HasValue && SelectedClassificationGUID.Value != Guid.Empty)
            {
                obj = obj.Where(a => a.ClassificationId == SelectedClassificationGUID);
            }

            if (SelectedSellerGUID.HasValue && SelectedSellerGUID.Value != Guid.Empty)
            {
                obj = obj.Where(a => a.SellerId == SelectedSellerGUID);
            }


            return(obj.Select(a => new Client()
            {
                ClientId = a.ClientId,
                Name = a.Name,
                Phone = a.Phone,
                Gender = a.Gender,
                LastPurchase = a.LastPurchase,
                Seller = new User()
                {
                    UserId = a.Seller.UserId,
                    Name = a.Seller.Name
                },
                Region = new Region()
                {
                    RegionId = a.Region.RegionId,
                    RegionName = a.Region.RegionName,
                    CityId = a.Region.CityId,
                    City = new City()
                    {
                        CityId = a.Region.City.CityId,
                        CityName = a.Region.City.CityName
                    }
                },
                Classification = new Classification()
                {
                    ClassificationId = a.Classification.ClassificationId,
                    ClassificationName = a.Classification.ClassificationName
                },
                Address = a.Address,
                Occupation = a.Occupation
            }));
        }