예제 #1
0
        public bool insert(Province pr)
        {
            bool flag = false;

            if (string.IsNullOrWhiteSpace(pr.ProvinceName))
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        _context.Province.Add(pr);
                        _context.SaveChanges();
                        _transaction.Commit();
                        flag = true;
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(flag);
        }
예제 #2
0
        public bool update(User user)
        {
            bool flag = false;

            if (user.UserId == null)
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        _context.Entry <User>(user).State = EntityState.Modified;
                        _context.SaveChanges();
                        _transaction.Commit();
                        flag = true;
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(flag);
        }
예제 #3
0
        public List <City> all()
        {
            List <City> cities = new List <City>();

            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        cities = (from c in _context.City
                                  select c).ToList <City>();
                        if (cities.Count() == 0)
                        {
                            return(cities);
                        }
                        else
                        {
                            _context.SaveChanges();
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(cities);
        }
예제 #4
0
        public bool update(City city)
        {
            bool flag = false;

            if (city.CityId == null)
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        _context.Entry <City>(city).State = EntityState.Modified;
                        _context.SaveChanges();
                        _transaction.Commit();
                        flag = true;
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(flag);
        }
예제 #5
0
        public bool new_admin(Admin admin)
        {
            bool flag = false;

            if (string.IsNullOrWhiteSpace(admin.Salt) || string.IsNullOrWhiteSpace(admin.Password) || string.IsNullOrWhiteSpace(admin.Email))
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        _context.Admin.Add(admin);
                        _context.SaveChanges();
                        _transaction.Commit();
                        flag = true;
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(flag);
        }
예제 #6
0
        public bool remove_by_id(Guid id)
        {
            bool flag = false;

            if (id == null)
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        //find addresses and delete
                        var addressId = (from a in _context.UserAddress
                                         where (a.UserId == id)
                                         select a).ToList <UserAddress>();
                        List <Address> addresses = new List <Address>();
                        foreach (var ads in addressId)
                        {
                            var adss = (from ad in _context.Address
                                        where (ad.AddressId == ads.AddressId)
                                        select ad).FirstOrDefault <Address>();
                            addresses.Add(adss);
                        }
                        _context.Address.RemoveRange(addresses);
                        _context.SaveChanges();

                        //remove user
                        var user = (from u in _context.User
                                    where (u.UserId == id)
                                    select u).FirstOrDefault <User>();
                        if (user == null)
                        {
                            _transaction.Rollback();
                            return(flag = false);
                        }
                        else
                        {
                            _context.User.Remove(user);
                            _context.SaveChanges();
                            _transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message, new Exception());
                    }
                }
            }
            return(flag);
        }
예제 #7
0
        public bool insert(City city)
        {
            bool flag = false;

            if (string.IsNullOrWhiteSpace(city.CityName) || city.CountryId == null || city.ProvinceId == null)
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }


                        _context.City.Add(city);
                        _context.SaveChanges();

                        _transaction.Commit();
                        flag = true;
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(flag);
        }
예제 #8
0
        static void Main(string[] args)
        {
            using (BlueContext context = new BlueContext())
            {
                context.Initialize(true);

                var customers = context.Customers.ToList();
            }

            Console.WriteLine("Oki");
        }
예제 #9
0
        public UserCities contact_home()
        {
            UserCities userCities = new UserCities();

            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        var users = (from u in _context.User
                                     select u).ToList <User>();
                        _context.SaveChanges();


                        var countries = (from c in _context.Country
                                         select(c)).ToList <Country>();
                        _context.SaveChanges();


                        if (users.Count() != 0)
                        {
                            userCities.Users = users;
                        }
                        if (countries.Count() != 0)
                        {
                            userCities.Countries = countries;
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(userCities);
        }
예제 #10
0
        public Admin show_by_email(string email)
        {
            Admin admin = new Admin();

            if (string.IsNullOrWhiteSpace(email) || !(email.Contains("@")))
            {
                return(admin);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        admin = (from a in _context.Admin
                                 where (a.Email == email)
                                 select a).FirstOrDefault <Admin>();
                        _context.SaveChanges();
                        if (admin == null)
                        {
                            _transaction.Rollback();
                            return(admin);
                        }
                        else
                        {
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(admin);
        }
예제 #11
0
        public Country search_by_name(string name)
        {
            Country country = new Country();

            if (string.IsNullOrWhiteSpace(name))
            {
                return(country);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }
                        country = (from c in _context.Country
                                   where
                                   (c.CountryName == name)
                                   select c).FirstOrDefault <Country>();
                        _context.SaveChanges();
                        if (country == null)
                        {
                            _transaction.Rollback();
                            return(country);
                        }
                        else
                        {
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(country);
        }
예제 #12
0
        public Admin show_admin(Guid id)
        {
            Admin admin = new Admin();

            if (id == null)
            {
                return(admin);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }
                        admin = (from a in _context.Admin
                                 where (a.AdminId == id)
                                 select a).FirstOrDefault <Admin>();
                        _context.SaveChanges();
                        if (admin == null)
                        {
                            _transaction.Rollback();
                            return(admin);
                        }
                        else
                        {
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }

            return(admin);
        }
예제 #13
0
        public Province search_by_name(string name)
        {
            Province province = new Province();

            if (string.IsNullOrWhiteSpace(name))
            {
                return(province);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }
                        province = (from p in _context.Province
                                    where
                                    (p.ProvinceName == name)
                                    select p).FirstOrDefault <Province>();
                        _context.SaveChanges();
                        if (province == null)
                        {
                            _transaction.Rollback();
                            return(province);
                        }
                        else
                        {
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(province);
        }
예제 #14
0
        public User show_by_id(Guid id)
        {
            User user = new User();

            if (id == null)
            {
                return(user);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        user = (from u in _context.User
                                where (u.UserId == id)
                                select u).FirstOrDefault <User>();
                        _context.SaveChanges();
                        if (user == null)
                        {
                            _transaction.Rollback();
                            return(user);
                        }
                        else
                        {
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(user);
        }
예제 #15
0
        public List <City> cities_by_province(Guid id)
        {
            List <City> cities = new List <City>();

            if (id == null)
            {
                return(cities);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }
                        cities = (from c in _context.City
                                  where (c.ProvinceId == id)
                                  select c).ToList <City>();
                        _context.SaveChanges();
                        if (cities.Count() == 0)
                        {
                            _transaction.Rollback();
                            return(cities);
                        }
                        else
                        {
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(cities);
        }
예제 #16
0
        public List <User> search_surname(string surname)
        {
            List <User> users = new List <User>();

            if (string.IsNullOrWhiteSpace(surname))
            {
                return(users);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        users = (from u in _context.User
                                 where (u.LastName.Contains(surname))
                                 select u).ToList <User>();
                        _context.SaveChanges();
                        if (users.Count() == 0)
                        {
                            _transaction.Rollback();
                            return(users);
                        }
                        _transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(users);
        }
예제 #17
0
        public bool remove(Province pr)
        {
            bool flag = false;

            if (pr.ProvinceId == null)
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        var province = (from p in _context.Province
                                        where (p.ProvinceId == pr.ProvinceId)
                                        select p).FirstOrDefault <Province>();
                        if (province == null)
                        {
                            return(flag = false);
                        }
                        else
                        {
                            _context.Province.Remove(province);
                            _context.SaveChanges();
                            _transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message, new Exception());
                    }
                }
            }
            return(flag);
        }
예제 #18
0
        public bool remove_by_id(Guid id)
        {
            bool flag = false;

            if (id == null)
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        var city = (from c in _context.City
                                    where (c.CityId == id)
                                    select c).FirstOrDefault <City>();
                        if (city == null)
                        {
                            return(flag = false);
                        }
                        else
                        {
                            _context.City.Remove(city);
                            _context.SaveChanges();
                            _transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message, new Exception());
                    }
                }
            }
            return(flag);
        }
예제 #19
0
        public List <Country> all()
        {
            List <Country> countries = new List <Country>();

            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        countries = (from c in _context.Country
                                     select c).ToList <Country>();
                        _context.SaveChanges();
                        if (countries.Count() == 0)
                        {
                            _context.Database.Connection.Close();
                            return(countries);
                        }
                        else
                        {
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }

            return(countries);
        }
예제 #20
0
        public bool remove(User user)
        {
            bool flag = false;

            if (user.UserId == null)
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        var ur = (from u in _context.User
                                  where (u.UserId == user.UserId)
                                  select u).FirstOrDefault <User>();
                        if (ur == null)
                        {
                            return(flag = false);
                        }
                        else
                        {
                            _context.User.Remove(ur);
                            _context.SaveChanges();
                            _transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message, new Exception());
                    }
                }
            }
            return(flag);
        }
예제 #21
0
        public City show_by_id(Guid id)
        {
            City city = new City();

            if (id == null)
            {
                return(city);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        city = (from c in _context.City
                                where (c.CityId == id)
                                select c).FirstOrDefault <City>();
                        if (city == null)
                        {
                            return(city);
                        }
                        else
                        {
                            _context.SaveChanges();
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(city);
        }
예제 #22
0
        public User show(User user)
        {
            User show = new User();

            if (user.UserId == null)
            {
                return(show);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        show = (from u in _context.User
                                where (u.UserId == user.UserId)
                                select u).FirstOrDefault <User>();
                        if (show == null)
                        {
                            return(user);
                        }
                        else
                        {
                            _context.SaveChanges();
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(show);
        }
예제 #23
0
        public Province show_by_id(Guid id)
        {
            Province province = new Province();

            if (id == null)
            {
                return(province);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        province = (from p in _context.Province
                                    where (p.ProvinceId == id)
                                    select p).FirstOrDefault <Province>();
                        if (province == null)
                        {
                            return(province);
                        }
                        else
                        {
                            _context.SaveChanges();
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(province);
        }
예제 #24
0
        public Country show(Country cou)
        {
            Country country = new Country();

            if (cou.CountryId == null)
            {
                return(country);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        country = (from c in _context.Country
                                   where (c.CountryId == cou.CountryId)
                                   select c).FirstOrDefault <Country>();
                        if (country == null)
                        {
                            return(country);
                        }
                        else
                        {
                            _context.SaveChanges();
                            _transaction.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(country);
        }
예제 #25
0
        public bool insert(User user, Address address)
        {
            bool flag = false;

            if (string.IsNullOrWhiteSpace(user.FirstName) || string.IsNullOrWhiteSpace(user.LastName) || string.IsNullOrWhiteSpace(address.AddressNumber))
            {
                return(flag = false);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }


                        //add user first
                        _context.User.Add(user);
                        _context.SaveChanges();
                        var user_id = user.UserId;

                        if (user_id == null)
                        {
                            _transaction.Rollback();
                            return(flag = false);
                        }

                        //add address for the user
                        _context.Address.Add(address);
                        _context.SaveChanges();
                        var addr_id = address.AddressId;

                        if (addr_id == null)
                        {
                            _transaction.Rollback();
                            return(flag = false);
                        }

                        //add user_adress
                        UserAddress userAddress = new UserAddress
                        {
                            AddressId = addr_id,
                            UserId    = user_id,
                        };
                        _context.UserAddress.Add(userAddress);
                        _context.SaveChanges();

                        _transaction.Commit();
                        flag = true;
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(flag);
        }
 public RoomsController(BlueContext context)
 {
     _context = context;
 }
예제 #27
0
        public List <User> search_first(PredictiveFilter filter)
        {
            List <User> users = new List <User>();

            if (string.IsNullOrWhiteSpace(filter.First))
            {
                return(users);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }


                        List <Address> addresses = new List <Address>();
                        if (filter.CountryId != Guid.Empty && filter.ProvinceId != Guid.Empty && filter.CityId != Guid.Empty)
                        {
                            addresses.Clear();
                            var ad1 = (from a in _context.Address
                                       where (a.CountryId == filter.CountryId && a.ProvinceId == filter.ProvinceId && a.CityId == filter.CityId)
                                       select a).ToList <Address>();
                            if (ad1.Count() != 0)
                            {
                                addresses.AddRange(ad1);
                            }


                            List <UserAddress> userAddresses = new List <UserAddress>();
                            if (addresses.Count() > 0)
                            {
                                userAddresses.Clear();
                                foreach (var a in addresses)
                                {
                                    var ads = (from ad in _context.UserAddress
                                               where (ad.AddressId == a.AddressId)
                                               select ad).SingleOrDefault <UserAddress>();
                                    userAddresses.Add(ads);
                                }
                            }

                            if (userAddresses.Count() > 0)
                            {
                                users.Clear();
                                foreach (var ds in userAddresses)
                                {
                                    var user = (from u in _context.User
                                                where (u.UserId == ds.UserId && u.FirstName.Contains(filter.First))
                                                select u).SingleOrDefault <User>();
                                    users.Add(user);
                                }
                                _context.SaveChanges();
                            }
                        }
                        else if (filter.CountryId != Guid.Empty && filter.ProvinceId != Guid.Empty && filter.CityId == Guid.Empty)
                        {
                            addresses.Clear();
                            var ad1 = (from a in _context.Address
                                       where (a.CountryId == filter.CountryId && a.ProvinceId == filter.ProvinceId)
                                       select a).ToList <Address>();
                            if (ad1.Count() != 0)
                            {
                                addresses.AddRange(ad1);
                            }

                            List <UserAddress> userAddresses = new List <UserAddress>();
                            if (addresses.Count() > 0)
                            {
                                userAddresses.Clear();
                                foreach (var a in addresses)
                                {
                                    var ads = (from ad in _context.UserAddress
                                               where (ad.AddressId == a.AddressId)
                                               select ad).SingleOrDefault <UserAddress>();
                                    userAddresses.Add(ads);
                                }
                            }

                            if (userAddresses.Count() > 0)
                            {
                                users.Clear();
                                foreach (var ds in userAddresses)
                                {
                                    var user = (from u in _context.User
                                                where (u.UserId == ds.UserId && u.FirstName.Contains(filter.First))
                                                select u).SingleOrDefault <User>();
                                    users.Add(user);
                                }
                                _context.SaveChanges();
                            }
                        }
                        else if (filter.CountryId != Guid.Empty && filter.ProvinceId == Guid.Empty && filter.CityId == Guid.Empty)
                        {
                            addresses.Clear();
                            var ad1 = (from a in _context.Address
                                       where (a.CountryId == filter.CountryId)
                                       select a).ToList <Address>();
                            if (ad1.Count() != 0)
                            {
                                addresses.AddRange(ad1);
                            }

                            List <UserAddress> userAddresses = new List <UserAddress>();
                            if (addresses.Count() > 0)
                            {
                                userAddresses.Clear();
                                foreach (var a in addresses)
                                {
                                    var ads = (from ad in _context.UserAddress
                                               where (ad.AddressId == a.AddressId)
                                               select ad).SingleOrDefault <UserAddress>();
                                    userAddresses.Add(ads);
                                }
                            }

                            if (userAddresses.Count() > 0)
                            {
                                users.Clear();
                                foreach (var ds in userAddresses)
                                {
                                    var user = (from u in _context.User
                                                where (u.UserId == ds.UserId && u.FirstName.Contains(filter.First))
                                                select u).SingleOrDefault <User>();
                                    users.Add(user);
                                }
                                _context.SaveChanges();
                            }
                        }
                        else if (filter.CountryId == Guid.Empty && filter.ProvinceId != Guid.Empty && filter.CityId != Guid.Empty)
                        {
                            addresses.Clear();
                            var ad1 = (from a in _context.Address
                                       where (a.ProvinceId == filter.ProvinceId && a.CityId == filter.CityId)
                                       select a).ToList <Address>();
                            if (ad1.Count() != 0)
                            {
                                addresses.AddRange(ad1);
                            }

                            List <UserAddress> userAddresses = new List <UserAddress>();
                            if (addresses.Count() > 0)
                            {
                                userAddresses.Clear();
                                foreach (var a in addresses)
                                {
                                    var ads = (from ad in _context.UserAddress
                                               where (ad.AddressId == a.AddressId)
                                               select ad).SingleOrDefault <UserAddress>();
                                    userAddresses.Add(ads);
                                }
                            }

                            if (userAddresses.Count() > 0)
                            {
                                users.Clear();
                                foreach (var ds in userAddresses)
                                {
                                    var user = (from u in _context.User
                                                where (u.UserId == ds.UserId && u.FirstName.Contains(filter.First))
                                                select u).SingleOrDefault <User>();
                                    users.Add(user);
                                }
                                _context.SaveChanges();
                            }
                        }
                        else if (filter.CountryId != Guid.Empty && filter.ProvinceId == Guid.Empty && filter.CityId != Guid.Empty)
                        {
                            addresses.Clear();
                            var ad1 = (from a in _context.Address
                                       where (a.CountryId == filter.CountryId && a.CityId == filter.CityId)
                                       select a).ToList <Address>();
                            if (ad1.Count() != 0)
                            {
                                addresses.AddRange(ad1);
                            }


                            List <UserAddress> userAddresses = new List <UserAddress>();
                            if (addresses.Count() > 0)
                            {
                                userAddresses.Clear();
                                foreach (var a in addresses)
                                {
                                    var ads = (from ad in _context.UserAddress
                                               where (ad.AddressId == a.AddressId)
                                               select ad).SingleOrDefault <UserAddress>();
                                    userAddresses.Add(ads);
                                }
                            }

                            if (userAddresses.Count() > 0)
                            {
                                users.Clear();
                                foreach (var ds in userAddresses)
                                {
                                    var user = (from u in _context.User
                                                where (u.UserId == ds.UserId && u.FirstName.Contains(filter.First))
                                                select u).SingleOrDefault <User>();
                                    users.Add(user);
                                }
                                _context.SaveChanges();
                            }
                        }
                        else if (filter.CountryId == Guid.Empty && filter.ProvinceId == Guid.Empty && filter.CityId != Guid.Empty)
                        {
                            addresses.Clear();
                            var ad1 = (from a in _context.Address
                                       where (a.CityId == filter.CityId)
                                       select a).ToList <Address>();
                            if (ad1.Count() != 0)
                            {
                                addresses.AddRange(ad1);
                            }
                            List <UserAddress> userAddresses = new List <UserAddress>();
                            if (addresses.Count() > 0)
                            {
                                userAddresses.Clear();
                                foreach (var a in addresses)
                                {
                                    var ads = (from ad in _context.UserAddress
                                               where (ad.AddressId == a.AddressId)
                                               select ad).SingleOrDefault <UserAddress>();
                                    userAddresses.Add(ads);
                                }
                            }

                            if (userAddresses.Count() > 0)
                            {
                                users.Clear();
                                foreach (var ds in userAddresses)
                                {
                                    var user = (from u in _context.User
                                                where (u.UserId == ds.UserId && u.FirstName.Contains(filter.First))
                                                select u).SingleOrDefault <User>();
                                    users.Add(user);
                                }
                                _context.SaveChanges();
                            }
                        }
                        else if (filter.CountryId == Guid.Empty && filter.ProvinceId != Guid.Empty && filter.CityId == Guid.Empty)
                        {
                            addresses.Clear();
                            var ad1 = (from a in _context.Address
                                       where (a.CityId == filter.CityId)
                                       select a).ToList <Address>();
                            if (ad1.Count() != 0)
                            {
                                addresses.AddRange(ad1);
                            }
                            List <UserAddress> userAddresses = new List <UserAddress>();
                            if (addresses.Count() > 0)
                            {
                                userAddresses.Clear();
                                foreach (var a in addresses)
                                {
                                    var ads = (from ad in _context.UserAddress
                                               where (ad.AddressId == a.AddressId)
                                               select ad).SingleOrDefault <UserAddress>();
                                    userAddresses.Add(ads);
                                }
                            }

                            if (userAddresses.Count() > 0)
                            {
                                users.Clear();
                                foreach (var ds in userAddresses)
                                {
                                    var user = (from u in _context.User
                                                where (u.UserId == ds.UserId && u.FirstName.Contains(filter.First))
                                                select u).SingleOrDefault <User>();
                                    users.Add(user);
                                }
                                _context.SaveChanges();
                            }
                        }
                        else
                        {
                            users = (from u in _context.User
                                     where (u.FirstName.Contains(filter.First))
                                     select u).ToList <User>();
                        }



                        if (users.Count() == 0)
                        {
                            _transaction.Rollback();
                            return(users);
                        }

                        _transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(users);
        }
예제 #28
0
 public CustomersController(BlueContext context)
 {
     _context = context;
 }
예제 #29
0
 public BookingsController(BlueContext context)
 {
     _context = context;
 }
예제 #30
0
        public FullUserInformation full_info(Guid id)
        {
            FullUserInformation fullUserInformation = new FullUserInformation();

            if (id == null || id == Guid.Empty)
            {
                return(fullUserInformation);
            }
            using (_context = new BlueContext())
            {
                using (var _transaction = _context.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (_context.Database.Connection.State == ConnectionState.Closed || _context.Database.Connection.State == ConnectionState.Broken)
                        {
                            _context.Database.Connection.Open();
                        }

                        var user = (from u in _context.User
                                    where (u.UserId == id)
                                    select u).SingleOrDefault <User>();
                        _context.SaveChanges();

                        var userAddress = (from us in _context.UserAddress
                                           where (us.UserId == user.UserId)
                                           select us).SingleOrDefault <UserAddress>();
                        _context.SaveChanges();

                        var address = (from a in _context.Address
                                       where (a.AddressId == userAddress.AddressId)
                                       select a).SingleOrDefault <Address>();
                        _context.SaveChanges();

                        var country = (from c in _context.Country
                                       where (c.CountryId == address.CountryId)
                                       select c).SingleOrDefault <Country>();
                        _context.SaveChanges();

                        var province = (from p in _context.Province
                                        where (p.ProvinceId == address.ProvinceId)
                                        select p).SingleOrDefault <Province>();
                        _context.SaveChanges();

                        var city = (from ci in _context.City
                                    where (ci.CityId == address.CityId)
                                    select ci).SingleOrDefault <City>();
                        _context.SaveChanges();

                        fullUserInformation.User     = user;
                        fullUserInformation.Address  = address;
                        fullUserInformation.Country  = country;
                        fullUserInformation.Province = province;
                        fullUserInformation.City     = city;

                        _transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        _transaction.Rollback();
                        throw new Exception(e.Message);
                    }
                }
            }
            return(fullUserInformation);
        }