示例#1
0
 public void SignUpUser(string email, string password)
 {
     try
     {
         GetUserByEmail(email);
     }
     catch (NonExistingUserException exception)
     {
         try
         {
             User user = new User()
             {
                 EMAIL = email, PASSWORD = password
             };
             using (var db = new TestTaskDBEntities())
             {
                 db.Users.Add(user);
                 db.SaveChanges();
             }
         }
         catch (Exception e)
         {
             throw new Exception(String.Format("Not Able to Add User: {0}", e.Message));
         }
     }
 }
示例#2
0
 public UserModel GetUserByEmail(string email)
 {
     using (var db = new TestTaskDBEntities())
     {
         var user = db.Users.FirstOrDefault(item => item.EMAIL == email);
         if (user == null) throw new NonExistingUserException("Given User does not exist");
         return (UserModel)userMapper.Map<User>(user);
     }
 }
示例#3
0
 public UserModel GetUserByUserID(int userId)
 {
     using (var db = new TestTaskDBEntities())
     {
         var user = db.Users.Find(userId);
         if (user == null)
         {
             throw new NonExistingUserException("Given User does not exist");
         }
         return((UserModel)userMapper.Map <User>(user));
     }
 }
示例#4
0
 public UserModel GetUserByEmail(string email)
 {
     using (var db = new TestTaskDBEntities())
     {
         var user = db.Users.FirstOrDefault(item => item.EMAIL == email);
         if (user == null)
         {
             throw new NonExistingUserException("Given User does not exist");
         }
         return((UserModel)userMapper.Map <User>(user));
     }
 }
示例#5
0
 public void SaveUserProvince(int userId, int provinceId)
 {
     using (var db = new TestTaskDBEntities())
     {
         var user = db.Users.Find(userId);
         if (user == null)
         {
             throw new NonExistingUserException("Given User does not exist");
         }
         user.PROVINCE = Convert.ToInt32(provinceId);
         db.SaveChanges();
     }
 }
示例#6
0
        public List<CountryModel> GetCountries()
        {
            var countryList = new List<CountryModel>();
            using (var db = new TestTaskDBEntities())
            {
                foreach (Country dbCountry in db.Countries)
                {
                    var country = (CountryModel)countryMapper.Map(dbCountry);
                    countryList.Add(country);
                }
            }

            return countryList;
        }
示例#7
0
        public List <CountryModel> GetCountries()
        {
            var countryList = new List <CountryModel>();

            using (var db = new TestTaskDBEntities())
            {
                foreach (Country dbCountry in db.Countries)
                {
                    var country = (CountryModel)countryMapper.Map(dbCountry);
                    countryList.Add(country);
                }
            }

            return(countryList);
        }
示例#8
0
 public List<ProvinceModel> GetProvinces(int countryId)
 {
     var provinceList = new List<ProvinceModel>();
     using (var db = new TestTaskDBEntities())
     {
         var provincesInCountry = from provinces in db.Provinces
                                  from countryProvinces in provinces.CountryProvinces
                                  where countryProvinces.COUNTRY_ID == countryId
                                  select provinces;
         foreach (Province dbProvince in provincesInCountry)
         {
             var province = (ProvinceModel)provinceMapper.Map(dbProvince);
             provinceList.Add(province);
         }
     }
     return provinceList;
 }
示例#9
0
        public List <ProvinceModel> GetProvinces(int countryId)
        {
            var provinceList = new List <ProvinceModel>();

            using (var db = new TestTaskDBEntities())
            {
                var provincesInCountry = from provinces in db.Provinces
                                         from countryProvinces in provinces.CountryProvinces
                                         where countryProvinces.COUNTRY_ID == countryId
                                         select provinces;
                foreach (Province dbProvince in provincesInCountry)
                {
                    var province = (ProvinceModel)provinceMapper.Map(dbProvince);
                    provinceList.Add(province);
                }
            }
            return(provinceList);
        }
示例#10
0
 public void SignUpUser(string email, string password)
 {
     try
     {
         GetUserByEmail(email);
     }
     catch (NonExistingUserException exception)
     {
         try
         {
             User user = new User() { EMAIL = email, PASSWORD = password };
             using (var db = new TestTaskDBEntities())
             {
                 db.Users.Add(user);
                 db.SaveChanges();
             }
         }
         catch (Exception e)
         {
             throw new Exception(String.Format("Not Able to Add User: {0}", e.Message));
         }
     }
 }
示例#11
0
 public void SaveUserProvince(int userId, int provinceId)
 {
     using (var db = new TestTaskDBEntities())
     {
         var user = db.Users.Find(userId);
         if (user == null) throw new NonExistingUserException("Given User does not exist");
         user.PROVINCE = Convert.ToInt32(provinceId);
         db.SaveChanges();
     }
 }
示例#12
0
 public UserModel GetUserByUserID(int userId)
 {
     using (var db = new TestTaskDBEntities())
     {
         var user = db.Users.Find(userId);
         if (user == null) throw new NonExistingUserException("Given User does not exist");
         return (UserModel)userMapper.Map<User>(user);
     }
 }