public Decimal GetLotPrice(Guid lotID)
        {
            Decimal price      = default(Decimal);
            var     connection = new SqlConnection(connectionString);

            try
            {
                connection.Open();
                var factory = new SqlCommandFactory(connection)
                              .AsStoredProcedure("[dbo].[SP_Lots_GetLotPrice]")
                              .WithParams()
                              .AddGuid("@lotID", lotID)
                              .AddMoneyOut("@lotPrice")
                              .ParamsEnd()
                              .ExecuteNonQuery();
                price = factory.GetParameter <Decimal>("@lotPrice");
            }
            catch (Exception)
            {
#if DEBUG
                throw;
#endif
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(price);
        }
        public Lot CreateLot(Guid auctionID, string title, string description, decimal startingPrice)
        {
            if (String.IsNullOrEmpty(title))
            {
                throw new ArgumentException("Lot title can not be blank.", "title");
            }
            if (String.IsNullOrEmpty(description))
            {
                throw new ArgumentException("Lot description can not be blank.", "description");
            }
            Lot lot        = null;
            var connection = new SqlConnection(connectionString);

            try
            {
                connection.Open();
                var factory = new SqlCommandFactory(connection)
                              .AsStoredProcedure("[dbo].[SP_Lots_CreateLot]")
                              .WithParams()
                              .AddGuid("@auctionID", auctionID)
                              .AddNVarChar("@lotTitle", title)
                              .AddNVarChar("@lotDescription", description)
                              .AddMoney("@startingPrice", startingPrice)
                              .AddGuidOut("@lotID")
                              .ParamsEnd()
                              .ExecuteNonQuery();
                lot = new Lot(
                    factory.GetParameter <Guid>("@lotID"),
                    auctionID,
                    title,
                    description,
                    startingPrice,
                    false
                    );
            }
            catch (Exception)
            {
#if DEBUG
                throw;
#endif
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(lot);
        }
        public Auction CreateAuction(Guid userID, string auctionTitle)
        {
            if (String.IsNullOrEmpty(auctionTitle))
            {
                throw new ArgumentException("Auction title can not be blank.", "auctionTitle");
            }
            Auction auction    = null;
            var     connection = new SqlConnection(connectionString);

            try
            {
                connection.Open();
                var factory = new SqlCommandFactory(connection)
                              .AsStoredProcedure("[dbo].[SP_Auctions_CreateAuction]")
                              .WithParams()
                              .AddGuid("@userID", userID)
                              .AddNVarChar("@auctionTitle", auctionTitle)
                              .AddBit("@isStarted", false)
                              .AddGuidOut("@auctionID")
                              .ParamsEnd()
                              .ExecuteNonQuery();
                auction = new Auction(
                    factory.GetParameter <Guid>("@auctionID"),
                    userID,
                    auctionTitle,
                    false,
                    false
                    );
            }
            catch (Exception)
            {
#if DEBUG
                throw;
#endif
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(auction);
        }
        public Bid CreateBid(Guid userID, Guid lotID, decimal price, DateTime bidDate)
        {
            Bid bid        = null;
            var connection = new SqlConnection(connectionString);

            try
            {
                connection.Open();
                var factory = new SqlCommandFactory(connection)
                              .AsStoredProcedure("[dbo].[SP_Bids_CreateBid]")
                              .WithParams()
                              .AddGuid("@userID", userID)
                              .AddGuid("@lotID", lotID)
                              .AddMoney("@price", price)
                              .AddDateTime("@bidDate", bidDate)
                              .AddGuidOut("@bidID")
                              .ParamsEnd()
                              .ExecuteNonQuery();
                bid = new Bid(
                    factory.GetParameter <Guid>("@bidID"),
                    userID,
                    lotID,
                    price,
                    bidDate
                    );
            }
            catch (Exception)
            {
#if DEBUG
                throw;
#endif
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(bid);
        }
예제 #5
0
        /// <summary>
        /// Create new role with specified name.
        /// </summary>
        /// <param name="roleName">Name of the role to create.</param>
        /// <returns>ID of the created role.</returns>
        public Role CreateRole(string roleName)
        {
            Role role       = null;
            var  connection = new SqlConnection(connectionString);

            try
            {
                connection.Open();
                var factory = new SqlCommandFactory(connection)
                              .AsStoredProcedure("[dbo].[SP_Roles_CreateRole]")
                              .WithParams()
                              .AddNVarChar("@roleName", roleName)
                              .AddGuidOut("@roleID")
                              .ParamsEnd()
                              .ExecuteNonQuery();
                role = new Role(
                    factory.GetParameter <Guid>("@roleID"),
                    roleName
                    );
            }
            catch (Exception)
            {
                // todo log exception.
#if DEBUG
                throw;
#endif
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(role);
        }
        public User CreateUser(string userName, DateTime registrationDate
                               , DateTime lastActivityDate, bool isLocked, string password
                               , string passwordSalt)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("userName can not be blank.", "userName");
            }
            if (userName.Length > 50)
            {
                throw new ArgumentException("userName can not be greater than 50 charachters.", "userName");
            }
            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentException("password can not be blank.", "password");
            }
            if (password.Length > 128)
            {
                throw new ArgumentException("password can not be greater than 128 characters.");
            }
            if (String.IsNullOrEmpty(passwordSalt))
            {
                throw new ArgumentException("passwordSalt can not be blank.", "passwordSalt");
            }
            if (passwordSalt.Length > 128)
            {
                throw new ArgumentException("passwordSalt can not be greater than 128 characters.");
            }
            User user       = null;
            var  connection = new SqlConnection(connectionString);

            try
            {
                connection.Open();
                var factory = new SqlCommandFactory(connection)
                              .AsStoredProcedure("[dbo].[SP_Users_CreateUser]")
                              .WithParams()
                              .AddNVarChar("@userName", userName)
                              .AddDateTime("@registrationDate", registrationDate)
                              .AddDateTime("@lastActivityDate", lastActivityDate)
                              .AddBit("@isLocked", isLocked)
                              .AddNVarChar("@password", password)
                              .AddNVarChar("@passwordSalt", passwordSalt)
                              .AddGuidOut("@userID")
                              .ParamsEnd()
                              .ExecuteNonQuery();
                user = new User(
                    factory.GetParameter <Guid>("@userID"),
                    userName,
                    registrationDate,
                    lastActivityDate,
                    isLocked
                    );
            }
            catch (Exception)
            {
                // todo log exception
#if DEBUG
                throw;
#endif
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(user);
        }