Example #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));
         }
     }
 }
Example #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);
     }
 }
Example #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));
     }
 }
Example #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));
     }
 }
Example #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();
     }
 }
Example #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;
        }
Example #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);
        }
Example #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;
 }
Example #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);
        }
Example #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));
         }
     }
 }
Example #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();
     }
 }
Example #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);
     }
 }