public void SetAccountInfo([FromBody] SetAccountInfo accountInfo)
        {
            //TODO: use transactions here and in any other multi-call endpoints
            var deletedRecords = DBFacilitator.GetInteger(
                PostgreSQLConnectionString,
                DELETE_ACCOUNT,
                new List <Tuple <string, string, NpgsqlDbType> >()
            {
                { new Tuple <string, string, NpgsqlDbType>(":UniqueId", accountInfo.UniqueId.ToString(), NpgsqlDbType.Integer) }
            });

            DBFacilitator.ExecuteCommand(
                PostgreSQLConnectionString,
                INSERT_ACCOUNT,
                new List <Tuple <string, string, NpgsqlDbType> >()
            {
                { new Tuple <string, string, NpgsqlDbType>(":UniqueId", accountInfo.UniqueId.ToString(), NpgsqlDbType.Integer) },
                { new Tuple <string, string, NpgsqlDbType>(":Email", accountInfo.AddressInfo.Email, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":FirstName", accountInfo.AddressInfo.FirstName, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":LastName", accountInfo.AddressInfo.LastName, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":Address1", accountInfo.AddressInfo.Address1, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":Address2", accountInfo.AddressInfo.Address2, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":City", accountInfo.AddressInfo.City, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":State", accountInfo.AddressInfo.State, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":Zip", accountInfo.AddressInfo.Zip, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":Country", accountInfo.AddressInfo.Country, NpgsqlDbType.Text) },
                { new Tuple <string, string, NpgsqlDbType>(":Phone", accountInfo.AddressInfo.Phone, NpgsqlDbType.Text) }
            });
        }
        public IList <CustomProfileInfo> GetProfileInfo([FromBody] ProfileInfo profileInfo)
        {
            string qualifiers = "";
            var    parameters = new List <Tuple <string, string, NpgsqlDbType> >();

            if (!string.IsNullOrEmpty(profileInfo.UsernameToMatch))
            {
                qualifiers += " AND Username LIKE :Username";
                parameters.Add(new Tuple <string, string, NpgsqlDbType>(":Username", profileInfo.UsernameToMatch, NpgsqlDbType.Text));
            }
            if (profileInfo.UserInactiveSinceDate != null)
            {
                qualifiers += " AND LastActivityDate >= :LastActivityDate";
                parameters.Add(new Tuple <string, string, NpgsqlDbType>("LastActivityDate", profileInfo.UserInactiveSinceDate.ToString(), NpgsqlDbType.Date));
            }
            if (profileInfo.AuthenticationOption != 2)
            {
                qualifiers += " AND IsAnonymous = " + (profileInfo.AuthenticationOption == 0 ? "TRUE" : "FALSE");
            }
            var totalRecords = DBFacilitator.GetInteger(
                PostgreSQLConnectionString,
                SELECT_PROFILE_COUNT + qualifiers,
                parameters);

            if (totalRecords <= 0)
            {
                return(new List <CustomProfileInfo>());
            }

            return(DBFacilitator.GetList <CustomProfileInfo>(
                       PostgreSQLConnectionString,
                       SELECT_PROFILES + qualifiers,
                       parameters));
        }
        public void PostOrder([FromBody] OrderInfo orderInfo)
        {
            int?highestOrderId = DBFacilitator.GetInteger(PostgreSQLConnectionString, SQL_GET_HIGHEST_ORDERID, new List <Tuple <string, string, NpgsqlDbType> >());

            highestOrderId = highestOrderId.HasValue ? highestOrderId + 1 : 0;

            var sb = new StringBuilder("");

            sb.Append("INSERT INTO \"MSPETSHOP4ORDERS\".Orders VALUES(");
            sb.Append("'" + highestOrderId + "', ");
            sb.Append("'" + orderInfo.UserId + "', ");
            sb.Append("'" + orderInfo.Date + "', ");
            sb.Append("'" + orderInfo.ShippingAddress.Address1 + "', ");
            sb.Append("'" + orderInfo.ShippingAddress.Address2 + "', ");
            sb.Append("'" + orderInfo.ShippingAddress.City + "', ");
            sb.Append("'" + orderInfo.ShippingAddress.State + "', ");
            sb.Append("'" + orderInfo.ShippingAddress.Zip + "', ");
            sb.Append("'" + orderInfo.ShippingAddress.Country + "', ");
            sb.Append("'" + orderInfo.BillingAddress.Address1 + "', ");
            sb.Append("'" + orderInfo.BillingAddress.Address2 + "', ");
            sb.Append("'" + orderInfo.BillingAddress.City + "', ");
            sb.Append("'" + orderInfo.BillingAddress.State + "', ");
            sb.Append("'" + orderInfo.BillingAddress.Zip + "', ");
            sb.Append("'" + orderInfo.BillingAddress.Country + "', ");
            sb.Append("'" + " UPS',");
            sb.Append("'" + orderInfo.OrderTotal + "', ");
            sb.Append("'" + orderInfo.BillingAddress.FirstName + "', ");
            sb.Append("'" + orderInfo.BillingAddress.LastName + "', ");
            sb.Append("'" + orderInfo.ShippingAddress.FirstName + "', ");
            sb.Append("'" + orderInfo.ShippingAddress.LastName + "', ");
            sb.Append("'" + orderInfo.AuthorizationNumber + "', ");
            sb.Append("'US-en');\n");


            sb.Append("INSERT INTO \"MSPETSHOP4ORDERS\".OrderStatus VALUES(");
            sb.Append("'" + highestOrderId + "', ");
            sb.Append("'" + "0', ");
            sb.Append("'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "', ");
            sb.Append("'P'");
            sb.Append(");\n");

            foreach (LineItemInfo info in orderInfo.LineItems)
            {
                sb.Append("INSERT INTO \"MSPETSHOP4ORDERS\".LineItem VALUES(");
                sb.Append("'" + highestOrderId + "', ");
                sb.Append("'" + info.Line + "', ");
                sb.Append("'" + info.ItemId + "', ");
                sb.Append("'" + info.Quantity + "', ");
                sb.Append("'" + info.Price);
                sb.Append("');\n");

                sb.Append("UPDATE \"MSPETSHOP4\".Inventory SET Qty = Qty - " + info.Quantity + " WHERE ItemId = '" + info.ItemId + "';\n");
            }

            DBFacilitator.ExecuteCommand(PostgreSQLConnectionString, sb.ToString(), new List <Tuple <string, string, NpgsqlDbType> >());
        }
 public int Create([FromBody] CreateProfile createProfileInfo)
 {
     return(DBFacilitator.GetInteger(
                PostgreSQLConnectionString,
                CREATE_USER,
                new List <Tuple <string, string, NpgsqlDbType> >()
     {
         { new Tuple <string, string, NpgsqlDbType>(":Username", createProfileInfo.Username, NpgsqlDbType.Text) },
         { new Tuple <string, string, NpgsqlDbType>(":ApplicationName", createProfileInfo.AppName, NpgsqlDbType.Text) },
         { new Tuple <string, string, NpgsqlDbType>(":LastActivityDate", DateTime.Now.ToString(), NpgsqlDbType.Date) },
         { new Tuple <string, string, NpgsqlDbType>(":LastUpdatedDate", DateTime.Now.ToString(), NpgsqlDbType.Date) },
         { new Tuple <string, string, NpgsqlDbType>(":IsAnonymous", createProfileInfo.IsAuthenticated ? "N" : "Y", NpgsqlDbType.Char) }
     }
                ).Value);
 }
        public bool DeleteProfile([FromBody] AccountInfo accountInfo)
        {
            var cart = GetUniqueID(new GetUniqueId(accountInfo.FirebaseGUID, false, true, accountInfo.AppName));

            if (cart != null)
            {
                int uniqueId       = cart.UniqueId;
                var deletedRecords = DBFacilitator.GetInteger(
                    PostgreSQLConnectionString,
                    DELETE_PROFILE,
                    new List <Tuple <string, string, NpgsqlDbType> >()
                {
                    { new Tuple <string, string, NpgsqlDbType>(":UniqueId", uniqueId.ToString(), NpgsqlDbType.Integer) }
                });
                return(deletedRecords == 0);
            }
            return(true);
        }