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;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
        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;
                }
            }
        }
Ejemplo n.º 4
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;
         }
     }
 }
Ejemplo n.º 5
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;
            }
        }
 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;
 }
Ejemplo n.º 7
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;
 }
 public City CreateCity(City city)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.CreateCity");
         db.AddInputParameter("@StateId", DbType.Int32, city.StateId);
         db.AddInputParameter("@State", DbType.String, city.State);
         db.AddInputParameter("@Name", DbType.String, city.Name);
         db.AddInputParameter("@PostalCode", DbType.String, city.PostalCode);                
         db.AddInputParameter("@Latitude", DbType.Double, city.Latitude);
         db.AddInputParameter("@Longitude", DbType.Double, city.Longitude);
         db.AddOutputParameter("@CityId", DbType.Int32);
         try
         {
             db.ExecuteNonQuery();
             city.CityId = db.GetParameterValue<int>("@CityId");
         }
         catch (Exception ex)
         {
             Logger.Error("Error while creating city.", ex);
             throw;
         }
     }
     return city;
 }
 public State CreateState(State state)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.CreateState");
         db.AddInputParameter("@CountryId", DbType.Int32, state.CountryId);
         db.AddInputParameter("@Country", DbType.String, state.Country);
         db.AddInputParameter("@Name", DbType.String, state.Name);
         db.AddInputParameter("@FullName", DbType.String, state.FullName);
         db.AddInputParameter("@Latitude", DbType.Double, state.Latitude);
         db.AddInputParameter("@Longitude", DbType.Double, state.Longitude);
         db.AddOutputParameter("@StateId", DbType.Int32);
         try
         {
             db.ExecuteNonQuery();
             state.StateId = db.GetParameterValue<int>("@StateId");
         }
         catch (Exception ex)
         {
             Logger.Error("Error while creating state.", ex);
             throw;
         }
     }
     return state;
 }
Ejemplo n.º 10
0
 public Country CreateCountry(Country country)
 {
     using (var db = new DataAccess())
     {
         db.CreateStoredProcCommand("dbo.CreateCountry");
         db.AddInputParameter("@Name", DbType.String, country.Name);
         db.AddInputParameter("@FullName", DbType.String, country.FullName);
         db.AddInputParameter("@Latitude", DbType.Double, country.Latitude);
         db.AddInputParameter("@Longitude", DbType.Double, country.Longitude);
         db.AddOutputParameter("@CountryId", DbType.Int32);
         try
         {
             db.ExecuteNonQuery();
             country.CountryId = db.GetParameterValue<int>("@CountryId");
         }
         catch (Exception ex)
         {
             Logger.Error("Error while creating country.", ex);
             throw;
         }
     }
     return country;
 }