public Donation CreateDonation(Donation donation)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.CreateDonation");
         db.AddInputParameter("@DonationProviderId", donation.DonationProviderId);
         db.AddInputParameter("@UserId", donation.UserId);
         db.AddInputParameter("@ExternalId", donation.ExternalId);
         db.AddInputParameter("@ExternalStatus", donation.ExternalStatus);
         db.AddInputParameter("@IsCompleted", donation.IsCompleted);
         db.AddInputParameter("@CountryId", donation.CountryId);
         db.AddInputParameter("@StateId", donation.StateId);
         db.AddInputParameter("@CityId", donation.CityId);
         db.AddInputParameter("@Amount", donation.Amount);
         db.AddInputParameter("@Currency", donation.Currency);
         db.AddInputParameter("@UserMessage", donation.UserMessage);
         db.AddInputParameter("@ProviderData", donation.ProviderXml);                
         db.AddInputParameter("@DonationSubscriptionId", donation.DonationSubscriptionId);
         db.AddInputParameter("@TransactionType", donation.TransactionType);
         db.AddOutputParameter("@DonationId", DbType.Int32);
         try
         {
             db.ExecuteNonQuery();
             donation.DonationId = db.GetParameterValue<int>("@DonationId");
         }
         catch (Exception ex)
         {
             Log.Error("Error while creating donation.", ex);
             throw;
         }
     }
     return donation;
 }
예제 #2
0
 public int CreateHero(Hero hero, IEnumerable<IPostedFile> photos)
 {
     var heroId = 0;
     using (var tran = new DbTransactionManager())
     {
         tran.BeginTransaction();
         using (var db = new DataAccess(tran))
         {
             db.CreateStoredProcCommand("dbo.CreateHero");
             db.AddInputParameter("@FirstName", DbType.String, hero.FirstName);
             db.AddInputParameter("@LastName", DbType.String, hero.LastName);
             db.AddInputParameter("@MiddleName", DbType.String, hero.MiddleName);
             db.AddInputParameter("@Dob", DbType.DateTime, hero.Dob);
             db.AddInputParameter("@Died", DbType.DateTime, hero.Died);
             db.AddInputParameter("@MilitaryGroupId", DbType.Int32, hero.MilitaryGroupId);
             db.AddInputParameter("@MilitaryRankId", DbType.Int32, hero.MilitaryRankId);
             db.AddInputParameter("@MilitaryAwardId", DbType.Int32, hero.MilitaryAwardId);
             db.AddInputParameter("@Biography", DbType.String, hero.Biography);
             db.AddInputParameter("@LanguageId", DbType.Int32, hero.LanguageId);
             db.AddInputParameter("@UpdatedBy", DbType.Int32, hero.UpdatedBy);
             db.AddInputParameter("@Photos", DbType.Xml, photos.ToDbXml());
             db.AddOutputParameter("@HeroId", DbType.Int32);
             try
             {
                 db.ExecuteNonQuery();
                 heroId = db.GetParameterValue<int>("@HeroId");
                 SaveBlobs(heroId, photos);
                 tran.Commit();
             }
             catch (SqlException ex)
             {
                 tran.Rollback();
                 Logger.Error("Error while creating hero", ex);
                 throw new RepositoryException("Oops! Something went wrong... :(", ex);
             }
             catch (Exception ex)
             {
                 tran.Rollback();
                 Logger.Error("Error while creating hero", ex);
                 throw new RepositoryException("Oops! Something went wrong... :(", ex);
             }
             return heroId;
         }
     }
 }
 public void UpdateUserMessage(Donation donation)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.UpdateUserMessage");
         db.AddInputParameter("@DonationId", DbType.Int32, donation.DonationId);
         db.AddInputParameter("@UserId", DbType.Int32, donation.UserId);
         db.AddInputParameter("@UserMessage", DbType.String, donation.UserMessage);
         try
         {
             db.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             Log.Error("Error while updating user message.", ex);
             throw;
         }
     }
 }
 public Donation RefundDonation(string externalId, string externalStatus)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.RefundDonation");
         db.AddInputParameter("@ExternalId", externalId);
         db.AddInputParameter("@ExternalStatus", externalStatus);
         try
         {
             var donation = new Donation();
             db.ReadInto(donation);
             return donation;
         }
         catch (Exception ex)
         {
             Log.Error("Error while refunding donation.", ex);
             throw;
         }
     }
 }
예제 #5
0
 public Hero GetRandomHero(int languageId)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.GetRandomHero");
         db.AddInputParameter("@LanguageId", DbType.Int32, languageId);
         var hero = new Hero();
         try
         {
             db.ReadInto(hero, hero.MilitaryGroup, hero.MilitaryRank, hero.MilitaryAward, hero.Photos);
             GetBlobs(hero, new CloudDataAccess());
         }
         catch (Exception ex)
         {
             Logger.Error("Error while getting random hero", ex);
             throw;
         }
         return hero;
     }
 }
        public User CreateUser(User user)
        {
            using (var tran = new DbTransactionManager())
            {
                tran.BeginTransaction();
                using (var db = new DataAccess(tran))
                {
                    try
                    {
                        db.CreateStoredProcCommand("dbo.CreateUser");
                        db.AddInputParameter("@Email", DbType.String, user.Email);
                        db.AddInputParameter("@DisplayName", DbType.String, user.DisplayName);
                        db.AddOutputParameter("@UserId", DbType.Int32);
                        db.ExecuteNonQuery();
                        user.UserId = db.GetParameterValue<int>("@UserId");

                        user.OAuth.UserId = user.UserId;
                        user.OAuth = CreateOAuthUser(user.OAuth, tran);

                        db.CreateStoredProcCommand("dbo.CreateUserProfile");
                        db.AddInputParameter("@UserId", DbType.String, user.UserId);
                        db.AddInputParameter("@LanguageId", DbType.String, user.Profile.Lang.LanguageId);
                        db.AddInputParameter("@Dob", DbType.String, user.Profile.Dob);
                        db.AddInputParameter("@Nationality", DbType.String, user.Profile.Nationality);
                        db.AddOutputParameter("@UserProfileId", DbType.Int32);
                        db.ExecuteNonQuery();
                        user.Profile.UserProfileId = db.GetParameterValue<int>("@UserProfileId");

                        user = GetUser(user.UserId);
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        Logger.Error("Error while creating user.", ex);
                        throw;
                    }
                    return user;
                }
            }
        }
 public IEnumerable<Language> GetLanguages()
 {
     List<Language> languages;
     if (!Cache.TryGetObject("Languages", out languages))
     {
         using (var db = new DataAccess())
         {
             db.CreateStoredProcCommand("dbo.GetLanguages");
             languages = new List<Language>();
             try
             {
                 db.ReadInto(languages);
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
     return languages;
 }
 public IEnumerable<MilitaryGroup> GetMilitaryGroups(int languageId)
 {
     List<MilitaryGroup> groups;
     if (!Cache.TryGetObject("MilitaryGroups" + languageId, out groups))
     {
         using (var db = new DataAccess())
         {
             db.CreateStoredProcCommand("dbo.GetMilitaryGroups");
             db.AddInputParameter("@LanguageId", DbType.Int32, languageId);
             groups = new List<MilitaryGroup>();
             try
             {
                 db.ReadInto(groups);
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
     return groups;
 }
 public User GetUser(int userId)
 {
     var user = new User();
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.GetUserByUserId");
         db.AddInputParameter("@UserId", DbType.Int32, userId);
         try
         {
             db.ReadInto(user,
                         user.Profile,
                         user.Profile.Lang,
                         user.OAuth,
                         user.Roles);
         }
         catch (Exception ex)
         {
             Logger.Error("Error while getting user.", ex);
             throw;
         }
     }
     return user;
 }
예제 #10
0
 public bool TryGetUserRegistered(string email, string provider, out int? userId, out bool isOAuthUser)
 {
     userId = null;
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.GetUserRegistered");
         db.AddInputParameter("@Email", DbType.String, email);
         db.AddInputParameter("@Provider", DbType.String, provider);
         db.AddOutputParameter("@UserId", DbType.Int32);
         db.AddOutputParameter("@IsOAuthUser", DbType.Boolean);
         try
         {
             db.ExecuteNonQuery();
             userId = db.GetParameterValue<int?>("@UserId");
             isOAuthUser = db.GetParameterValue<bool>("@IsOAuthUser");
         }
         catch (Exception ex)
         {
             Logger.Error("Error while checking registered user.", ex);
             throw;
         }
     }
     return userId.HasValue;
 }
예제 #11
0
 public void UpdateUserProfile(UserProfile profile)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.UpdateUserProfile");
         db.AddInputParameter("@UserId", DbType.Int32, profile.UserId);
         db.AddInputParameter("@LanguageId", DbType.String, profile.Lang.LanguageId);
         db.AddInputParameter("@Dob", DbType.String, profile.Dob);
         db.AddInputParameter("@Nationality", DbType.String, profile.Nationality);
         try
         {
             db.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             Logger.Error("Error while updating user profile.", ex);
             throw;
         }
     }
 }
 public DonationSubscription GetDonationSubscription(string subscriptionId)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.GetDonationSubscription");
         db.AddInputParameter("@SubscriptionId", subscriptionId);
         try
         {
             var subscription = new DonationSubscription();
             db.ReadInto(subscription);
             return subscription;
         }
         catch (Exception ex)
         {
             Log.Error("Error while gettng subscription.", ex);
             throw;
         }
     }
 }
 public DonationSubscription CreateDonationSubscription(DonationSubscription subscription)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.CreateDonationSubscription");
         db.AddInputParameter("@StartDate", subscription.StartDate);
         db.AddInputParameter("@EndDate", subscription.EndDate);
         db.AddInputParameter("@RecurrenceTimes", subscription.RecurrenceTimes);
         db.AddInputParameter("@SubscriptionId", subscription.SubscriptionId);
         db.AddInputParameter("@UserId", subscription.UserId);
         db.AddInputParameter("@Username", subscription.Username);
         db.AddInputParameter("@Password", subscription.Password);
         db.AddInputParameter("@ProviderData", subscription.ProviderXml);
         db.AddOutputParameter("@DonationSubscriptionId", DbType.Int32);
         try
         {
             db.ExecuteNonQuery();
             subscription.DonationSubscriptionId = db.GetParameterValue<int>("@DonationSubscriptionId");
         }
         catch (Exception ex)
         {
             Log.Error("Error while crating subscription.", ex);
             throw;
         }
     }
     return subscription;
 }
예제 #14
0
 public IEnumerable<User> SearchUsers(string name = null)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.SearchUsers");
         db.AddInputParameter("@StartsWith", DbType.String, name);
         try
         {
             var users = new List<User>();
             db.ReadInto(users);
             return users;
         }
         catch (Exception ex)
         {
             Logger.Error("Error while searching users.", ex);
             throw;
         }
     }
 }
예제 #15
0
 private OAuthUser CreateOAuthUser(OAuthUser user, DbTransactionManager tran)
 {
     using (var db = new DataAccess(tran))
     {
         db.CreateStoredProcCommand("dbo.CreateOAuthUser");
         db.AddInputParameter("@UserId", DbType.String, user.UserId);
         db.AddInputParameter("@Email", DbType.String, user.Email);
         db.AddInputParameter("@ProviderId", DbType.String, user.ProviderId);
         db.AddInputParameter("@ProviderName", DbType.String, user.ProviderName);
         db.AddInputParameter("@ProviderData", DbType.Xml, user.ProviderData.ToDbXml());
         db.AddOutputParameter("@OAuthUserId", DbType.Int32);
         try
         {
             db.ExecuteNonQuery();
             user.OAuthUserId = db.GetParameterValue<int>("@OAuthUserId");
         }
         catch (Exception ex)
         {
             Logger.Error("Error while creating OAuth user", ex);
             throw;
         }
     }
     return user;
 }
예제 #16
0
        public HeroSearchCriteria SearchHeros(HeroSearchCriteria criteria)
        {
            var heros = new List<Hero>();
            var photos = new List<HeroPhoto>();

            using (var db = new DataAccess())
            {
                db.CreateStoredProcCommand("dbo.GetHeros");
                db.AddInputParameter("@PageNo", DbType.Int32, criteria.PageNo);
                db.AddInputParameter("@Name", DbType.String, criteria.Name);
                db.AddInputParameter("@PageSize", DbType.Int32, criteria.PageSize);
                db.AddInputParameter("@LanguageId", DbType.Int32, criteria.LanguageId);
                db.AddOutputParameter("@TotalCount", DbType.Int32);
                try
                {
                    db.ReadInto(heros, photos);
                    heros.ForEach(x => x.Photos = photos.Where(y => y.HeroId == x.HeroId));
                    GetBlobs(heros, new CloudDataAccess());
                    criteria.Result = heros;
                    criteria.TotalCount = db.GetParameterValue<int>("@TotalCount");
                }
                catch (Exception ex)
                {
                    Logger.Error("Error while searching hero", ex);
                    throw;
                }
                return criteria;
            }
        }
예제 #17
0
        public void UpdateHero(Hero hero, IEnumerable<IPostedFile> photos)
        {
            using (var tran = new DbTransactionManager())
            {
                try
                {
                    tran.BeginTransaction();
                    using (var db = new DataAccess(tran))
                    {
                        db.CreateStoredProcCommand("dbo.UpdateHero");
                        db.AddInputParameter("@HeroId", DbType.Int32, hero.HeroId);
                        db.AddInputParameter("@FirstName", DbType.String, hero.FirstName);
                        db.AddInputParameter("@LastName", DbType.String, hero.LastName);
                        db.AddInputParameter("@MiddleName", DbType.String, hero.MiddleName);
                        db.AddInputParameter("@Dob", DbType.DateTime, hero.Dob);
                        db.AddInputParameter("@Died", DbType.DateTime, hero.Died);
                        db.AddInputParameter("@MilitaryGroupId", DbType.Int32, hero.MilitaryGroupId);
                        db.AddInputParameter("@MilitaryRankId", DbType.Int32, hero.MilitaryRankId);
                        db.AddInputParameter("@MilitaryAwardId", DbType.Int32, hero.MilitaryAwardId);
                        db.AddInputParameter("@Biography", DbType.String, hero.Biography);
                        db.AddInputParameter("@LanguageId", DbType.Int32, hero.LanguageId);
                        db.AddInputParameter("@UpdatedBy", DbType.Int32, hero.UpdatedBy);
                        db.AddInputParameter("@Photos", DbType.Xml, photos.ToDbXml());

                        db.ExecuteNonQuery();
                        SaveBlobs(hero.HeroId.Value, photos);
                        tran.Commit();
                    }
                }
                catch (Exception ex)
                {                    
                    tran.Rollback();
                    Logger.Error("Error while updating hero", ex);
                    throw;
                }
            }
        }
 public bool SubscriptionCompleted(string subscriptionId)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.GetSubscriptionCompleted");
         db.AddInputParameter("@SubscriptionId", subscriptionId);
         try
         {
             return db.ExecuteScalar<bool>();
         }
         catch (Exception ex)
         {
             Log.Error("Error while validating transaction.", ex);
             throw;
         }
     }
 }
예제 #19
0
 public UserContactInfo GetUserContactInfo(int userId)
 {
     using (var db = new DataAccess())
     {
         try
         {
             db.CreateStoredProcCommand("dbo.GetUserContactInfo");
             db.AddInputParameter("@UserId", DbType.Int32, userId);
             var info = new UserContactInfo();
             info.Address = new Address();
             db.ReadInto(info);
             return info;
         }
         catch (Exception ex)
         {
             Logger.Error("Error while getting user contact info.", ex);
             throw;
         }
     }            
 }
예제 #20
0
 public void RevokeUserFromRoles(int userId, IEnumerable<int> roles)
 {
     using (var tran = new DbTransactionManager())
     {
         tran.BeginTransaction();
         using (var db = new DataAccess(tran))
         {
             try
             {
                 db.CreateStoredProcCommand("dbo.RevokeUserFromRole");
                 foreach (var id in roles)
                 {
                     db.AddInputParameter("@UserId", DbType.Int32, userId);
                     db.AddInputParameter("@RoleId", DbType.Int32, id);
                     db.ExecuteNonQuery();
                     db.ResetCommand(false);
                 }
                 tran.Commit();
             }
             catch (Exception ex)
             {
                 tran.Rollback();
                 Logger.Error("Error while revoking roles.", ex);
                 throw;
             }
         }
     }
 }
예제 #21
0
 public IEnumerable<Role> GetUserRoles(int userId)
 {
     using (var db = new DataAccess())
     {
         try
         {
             db.CreateStoredProcCommand("dbo.GetUserRoles");
             db.AddInputParameter("@UserId", DbType.Int32, userId);
             var roles = new List<Role>();
             db.ReadInto(roles);
             return roles;
         }
         catch (Exception ex)
         {
             Logger.Error("Error while getting user roles.", ex);
             throw;
         }
     }
 }
예제 #22
0
        public void UpdateUser(User user)
        {
            using (var tran = new DbTransactionManager())
            {
                tran.BeginTransaction();
                using (var db = new DataAccess(tran))
                {
                    db.CreateStoredProcCommand("dbo.UpdateUser");
                    db.AddInputParameter("@UserId", DbType.Int32, user.UserId);
                    db.AddInputParameter("@Email", DbType.String, user.Email);
                    db.AddInputParameter("@DisplayName", DbType.String, user.DisplayName);
                    try
                    {
                        db.ExecuteNonQuery();

                        if (user.Profile != null)
                        {
                            UpdateUserProfile(user.Profile);
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        Logger.Error("Error while updating user.", ex);
                        throw;
                    }
                }
            }
        }
 public void CompleteTransaction(Donation donation)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.CompleteDonation");
         db.AddInputParameter("@ExternalId", DbType.String, donation.ExternalId);
         db.AddInputParameter("@ExternalStatus", DbType.String, donation.ExternalStatus);
         db.AddInputParameter("@IsCompleted", DbType.Boolean, donation.IsCompleted);
         db.AddInputParameter("@CountryId", DbType.Int32, donation.CountryId);
         db.AddInputParameter("@StateId", DbType.Int32, donation.StateId);
         db.AddInputParameter("@CityId", DbType.Int32, donation.CityId);
         try
         {
             db.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             Log.Error("Error while verifying donation.", ex);
             throw;
         }
     }
 }
 public DonationSearchCriteria SearchDonations(DonationSearchCriteria criteria)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.SearchDonations");
         db.AddInputParameter("@UserId", DbType.Int32, criteria.UserId);
         db.AddInputParameter("@Name", DbType.String, criteria.Name);
         db.AddInputParameter("@FromDate", DbType.DateTime, criteria.FromDate.ToFromDate());
         db.AddInputParameter("@ToDate", DbType.DateTime, criteria.ToDate.ToToDate());
         try
         {
             criteria.Result = new List<Donation>();
             db.ReadInto(criteria.Result);
         }
         catch (Exception ex)
         {
             Log.Error("Error while searching donations.", ex);
             throw;
         }
         return criteria;
     }   
 }
예제 #25
0
 public HeroPhoto DeletePhoto(int heroPhotoId)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.DeleteHeroPhoto");
         db.AddInputParameter("@HeroPhotoId", DbType.Int32, heroPhotoId);
         var photo = new HeroPhoto();
         try
         {
             db.ReadInto(photo);
             DeleteBlob(photo);
         }
         catch (Exception ex)
         {
             Logger.Error("Error while deleting hero", ex);
             throw;
         }
         return photo;
     }
 }
 private List<MapPoint> GetDonationLocations(string sproc, MapPoint northwest, MapPoint southeast)  
 {            
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand(sproc);
         db.AddInputParameter("@NwLat", DbType.Double, northwest.Latitude);
         db.AddInputParameter("@NwLng", DbType.Double, northwest.Longitude);
         db.AddInputParameter("@SeLat", DbType.Double, southeast.Latitude);
         db.AddInputParameter("@SeLng", DbType.Double, southeast.Longitude);
         try
         {
             var points = new List<MapPoint>();
             db.ReadInto(points);
             return points;
         }
         catch (Exception ex)
         {
             Log.Error("Error while searching donations.", ex);
             throw;
         }
     }  
 }
예제 #27
0
 public IEnumerable<string> GetAlphabet(int languageId)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.GetHeroAlphabet");
         db.AddInputParameter("@LanguageId", DbType.String, languageId);
         try
         {
             var alphabet = new List<string>();
             db.ReadInto(alphabet);
             return alphabet;
         }
         catch (Exception ex)
         {
             Logger.Error("Error while getting alphabet", ex);
             throw;
         }
     }
 }
예제 #28
0
 public void UpdateUserProfileAddress(int userId, Address address)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.UpdateUserProfileAddress");                
         db.AddInputParameter("@UserId", DbType.Int32, userId);
         db.AddInputParameter("@Street", DbType.String, address.Street);
         db.AddInputParameter("@CityId", DbType.String, address.CityId);
         db.AddInputParameter("@StateId", DbType.String, address.StateId);
         db.AddInputParameter("@CountryId", DbType.String, address.CountryId);
         db.AddInputParameter("@Latitude", DbType.Double, address.Latitude);
         db.AddInputParameter("@Longitude", DbType.Double, address.Longitude);
         try
         {
             db.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             Logger.Error("Error while updating user profile address.", ex);
             throw;
         }
     }
 }
 public string GetUserMessage(int donationId)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.GetDonationMessage");
         db.AddInputParameter("@DonationId", DbType.Int32, donationId);
         try
         {
             return db.ExecuteScalar<string>();
         }
         catch (Exception ex)
         {
             Log.Error("Error while updating user message.", ex);
             throw;
         }
     }
 }
예제 #30
0
 public IEnumerable<User> GetUsers()
 {
     using (var db = new DataAccess())
     {
         try
         {
             db.CreateStoredProcCommand("dbo.GetUsers");
             var users = new List<User>();
             db.ReadInto(users);
             return users;
         }
         catch (Exception ex)
         {
             Logger.Error("Error while getting user.", ex);
             throw;
         }
     }
 }