Exemplo n.º 1
0
        public async Task <IHttpActionResult> GetOrders(string invno)
        {
            var processingResult = new ServiceProcessingResult <List <OrderData> > {
                IsSuccessful = true
            };
            var parameters = new MySqlParameter[] {
                new MySqlParameter("@Invno", invno)
            };
            var sqlText = @"
              SELECT orders.Teacher,  orders.ItemAmount, orders.Itemqty, orders.OrderId, orders.OrdDate, orders.Grade, orders.Studentfname, orders.Studentlname, orders.Itemtotal,  orders.Booktype, orders.Emailaddress, orders.Perstext1,orders.Paytype, orders.Schname, payment.Transid,L1.caption as 'Icon1',L2.caption as 'Icon2',L3.caption as 'Icon3',L4.caption as 'Icon4',payment.Payerfname,payment.Payerlname  FROM orders INNER JOIN payment ON orders.orderid = payment.orderid left join lookup as L1 on orders.icon1=L1.ivalue left join lookup as L2 on orders.icon2=L2.ivalue left join lookup as L3 on orders.icon3=L3.ivalue left join lookup as L4 on orders.icon4=L4.ivalue WHERE (orders.schinvoicenumber = @Invno)  ORDER BY orders.orddate, orders.orderid";

            var sqlQuery       = new SQLQuery();
            var getOrderResult = await sqlQuery.ExecuteReaderAsync <OrderData>(CommandType.Text, sqlText, parameters);

            if (!getOrderResult.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error retrieving orders.", "Error retrieving orders.", true, false);
                return(Ok(processingResult));
            }
            var orderlist = (List <OrderData>)getOrderResult.Data;

            processingResult.Data = orderlist;
            return(Ok(processingResult));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> AddTeacher(TeacherData model)
        {
            var processingResult = new ServiceProcessingResult <bool> {
                IsSuccessful = true
            };
            var parameters = new MySqlParameter[] {
                new MySqlParameter("@Schcode", model.Schcode),
                new MySqlParameter("@Teacher", model.Teacher),
                new MySqlParameter("@Grade", model.Grade)
            };
            var sqlText = @"
               Insert Into DropDownInfo (Schcode,Teacher,Grade) VALUES(@Schcode,@Teacher,@Grade)
              ";

            var sqlQuery = new SQLQuery();
            var Result   = await sqlQuery.ExecuteNonQueryAsync(CommandType.Text, sqlText, parameters);

            if (!Result.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error inserting teacher.", "Error inserting teacher.", true, false);
                return(Ok(processingResult));
            }
            if (Result.Data < 1)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error inserting teacher.", "Error inserting teacher.", true, false);
                return(Ok(processingResult));
            }

            processingResult.Data = true;
            return(Ok(processingResult));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> DeleteTeacher(string id)
        {
            var processingResult = new ServiceProcessingResult <bool> {
                IsSuccessful = true
            };
            var parameters = new MySqlParameter[] {
                new MySqlParameter("@Id", id),
            };
            var sqlText = @"
               Delete From DropDownInfo Where Id=@Id
              ";

            var sqlQuery = new SQLQuery();
            var Result   = await sqlQuery.ExecuteNonQueryAsync(CommandType.Text, sqlText, parameters);

            if (!Result.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error deleting teacher.", "Error deleting teacher.", true, false);
                return(Ok(processingResult));
            }
            if (Result.Data < 1)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error deleting teacher.", "Error deleting teacher.", true, false);
                return(Ok(processingResult));
            }

            processingResult.Data = true;
            return(Ok(processingResult));
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> GetAllTeachers(string schcode)
        {
            var processingResult = new ServiceProcessingResult <List <TeacherData> > {
                IsSuccessful = true
            };

            var sqlQuery = new SQLQuery();
            var sqlText  = "Select Teacher,Grade,Schcode,Id from DropDownInfo Where Schcode=@Schcode Order By Teacher";

            MySqlParameter[] parameters = new MySqlParameter[] {
                new MySqlParameter("@Schcode", schcode),
            };
            var getTeacherResult = await sqlQuery.ExecuteReaderAsync <TeacherData>(CommandType.Text, sqlText, parameters);

            if (!getTeacherResult.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Failed to retrieve teachers.", "Failed to retrieve teachers.", true, false);
                ExceptionlessClient.Default.CreateLog("Failed to retrieve teachers.", "Error").AddObject(schcode).Submit();
                return(Ok(processingResult));
            }
            var teacherList = (List <TeacherData>)getTeacherResult.Data;

            processingResult.Data = teacherList;
            return(Ok(processingResult));
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> InvoiceCodeExist(string invNumber)
        {
            var processingResult = new ServiceProcessingResult <bool> {
                IsSuccessful = true
            };

            try {
                var sqlQuery = "SELECT Invno FROM InvoiceInfo WHERE Invno=@InvNumber";
                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@InvNumber", invNumber) };
                var sqlQueryService         = new SQLQuery();
                var getInoviceCodeResult    = await sqlQueryService.ExecuteReaderAsync(CommandType.Text, sqlQuery, parameters);

                if (!getInoviceCodeResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting invoice code", "Error getting invoice code", true, false);
                    return(Ok(processingResult));
                }

                if (getInoviceCodeResult.Data.Rows.Count > 0)
                {
                    processingResult.Data = true;
                }
                else
                {
                    processingResult.Data = false;
                }
            } catch (Exception ex) {
                ex.ToExceptionless().Submit();
            }
            return(Ok(processingResult));
        }
Exemplo n.º 6
0
        public async Task <ServiceProcessingResult <int> > ExecuteNonQueryAsync(CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            var result = new ServiceProcessingResult <int> {
                IsSuccessful = true
            };

            using (var connection = new MySqlConnection(_ConnectionString)) {
                using (var command = new MySqlCommand(cmdText, connection)) {
                    try {
                        command.CommandType = cmdType;
                        command.Parameters.Clear();
                        command.Parameters.AddRange(commandParameters);
                        connection.Open();

                        var sqlResult = await command.ExecuteNonQueryAsync();

                        result.Data = sqlResult;
                    } catch (Exception ex) {
                        result.IsSuccessful = false;
                        ex.ToExceptionless()
                        .SetMessage("Error running ExecuteNonQueryAsync.")
                        .AddTags("Sql Query Wrapper")
                        .AddObject(cmdText, "Query")
                        .AddObject(CommandParametersToObj(commandParameters), "Query Parameters")
                        .MarkAsCritical()
                        .Submit();
                        result.Error = new ProcessingError("Error processing ExecuteNonQueryAsync", "Error processing ExecuteNonQueryAsync", true, false);
                    } finally {
                        connection.Close();
                    }

                    return(result);
                }
            }
        }
Exemplo n.º 7
0
        public async Task <ServiceProcessingResult <object> > ExecuteReaderAsync <T>(CommandType cmdType, string cmdText, int TimeoutInSeconds, params MySqlParameter[] commandParameters)
        {
            var processingResult = new ServiceProcessingResult <object> {
                IsSuccessful = true
            };

            using (var connection = new MySqlConnection(_ConnectionString)) {
                using (var command = new MySqlCommand(cmdText, connection)) {
                    try {
                        var dt = new DataTable();
                        command.CommandType = cmdType;
                        command.Parameters.Clear();
                        command.Parameters.AddRange(commandParameters);
                        command.CommandTimeout = TimeoutInSeconds;
                        connection.Open();

                        using (MySqlDataAdapter a = new MySqlDataAdapter(command)) {
                            a.Fill(dt);
                        }

                        if (dt.Rows.Count < 1)
                        {
                            processingResult.Data = null;
                            return(processingResult);
                        }
                        try {
                            var Vals = CollectionHelper.ConvertTo <T>(dt);
                            processingResult.Data = Vals;
                        } catch (Exception ex) {
                            processingResult.IsSuccessful = false;
                            processingResult.Error        = new ProcessingError("Error retrieving data.", "Error retrieving data.", true, false);

                            ex.ToExceptionless()
                            .SetMessage("Collection Helper Error")
                            .AddTags("Collection Helper")
                            .MarkAsCritical()
                            .Submit();
                        }

                        return(processingResult);
                    } catch (Exception ex) {
                        processingResult.IsSuccessful = false;

                        ex.ToExceptionless()
                        .SetMessage("Error running ExecuteReaderAsync(object).")
                        .AddTags("Sql Query Wrapper")
                        .AddObject(cmdText, "Query")
                        .AddObject(CommandParametersToObj(commandParameters), "Query Parameters")
                        .MarkAsCritical()
                        .Submit();
                        processingResult.Error = new ProcessingError("Error running ExecuteReaderAsync. Ex: " + ex.ToString(), "Error running ExecuteReaderAsync. Ex: " + ex.ToString(), false, false);
                        return(processingResult);
                    } finally {
                        connection.Close();
                    }
                }
            }
        }
Exemplo n.º 8
0
        public async Task <IHttpActionResult> Login(Credentials cred)
        {
            var processingResult = new ServiceProcessingResult <LoginReturn> {
                IsSuccessful = true
            };


            try
            {
                var sqlQuery = "SELECT schcode,schname,invno FROM InvoiceInfo WHERE Schcode=@Schcode AND Invno=@Invno";
                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@Invno", cred.password), new MySqlParameter("@Schcode", cred.schcode) };
                var sqlQueryService         = new SQLQuery();
                var getLoginResult          = await sqlQueryService.ExecuteReaderAsync <LoginReturn>(CommandType.Text, sqlQuery, parameters);

                if (!getLoginResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Failed to login.", "Failed to login.", true, false);
                    ExceptionlessClient.Default.CreateLog(typeof(InvoiceController).FullName, "Login failed", "Error").AddObject(cred).AddTags("Controller Error").Submit();
                    return(Ok(processingResult));
                }
                var retval = (List <LoginReturn>)getLoginResult.Data;
                if (retval == null)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Improper Credeintials.", "Improper Credentials.", true, false);
                    return(Ok(processingResult));
                }
                if (retval.Count == 1)
                {
                    processingResult.Data = retval[0];
                }
                else
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Improper Credeintials.", "Improper Credentials.", true, false);
                }
                return(Ok(processingResult));
            }
            catch (Exception ex)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Failed to login.", "Failed to login.", true, false);
                ex.ToExceptionless()
                .SetMessage("Login Failed")
                .Submit();
                return(Ok(processingResult));
            }
        }
Exemplo n.º 9
0
        public async Task <IHttpActionResult> SchoolExist(string schcode)
        {
            var processingResult = new ServiceProcessingResult <SchoolExist> {
                IsSuccessful = true
            };

            try
            {
                var sqlQuery = @"Select Schname,Schcode from Cust where Schcode=@Schcode";
                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@Schcode", schcode) };
                var sqlQueryService         = new SQLQuery();
                var getSchoolResult         = await sqlQueryService.ExecuteReaderAsync <SchoolExist>(CommandType.Text, sqlQuery, parameters);

                if (!getSchoolResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error looking up school.", "Error looking up school.", true, false);
                    ExceptionlessClient.Default.CreateLog("Error looking up school.")
                    .MarkAsCritical()
                    .AddObject(schcode);
                    return(Ok(processingResult));
                }

                processingResult.IsSuccessful = true;

                var result = (List <SchoolExist>)getSchoolResult.Data;
                if (result == null)
                {
                    processingResult.Data = null;
                }
                else
                {
                    processingResult.Data = result[0];//only one record }
                }
            }
            catch (Exception ex)
            {
                ex.ToExceptionless()
                .SetMessage("Error looing up school code.")
                .Submit();
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error looking up school.", "Error looking up school.", true, false);
                return(Ok(processingResult));
            }
            return(Ok(processingResult));
        }
Exemplo n.º 10
0
        public async Task <IHttpActionResult> GetStates()


        {
            var processingResult = new ServiceProcessingResult <List <StateBindingModel> > {
                IsSuccessful = true
            };

            try {
                var sqlQuery = "SELECT * FROM states order by name";
                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@InvNumber", "1") };
                var sqlQueryService         = new SQLQuery();
                var stateResult             = await sqlQueryService.ExecuteReaderAsync(CommandType.Text, sqlQuery, parameters);

                if (!stateResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting states", "Error getting ", true, false);
                    return(Ok(processingResult));
                }

                if (stateResult.Data.Rows.Count > 0)
                {
                    List <StateBindingModel> States = new List <StateBindingModel>();
                    foreach (DataRow row in stateResult.Data.Rows)
                    {
                        StateBindingModel state = new StateBindingModel();
                        state.Abrv = row["abrv"].ToString();
                        state.Name = row["name"].ToString();
                        States.Add(state);
                    }
                    processingResult.Data         = States;
                    processingResult.IsSuccessful = true;
                }
                else
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Failed to retrieve states", "Failed to retrieve states", true, false);
                }
            } catch (Exception ex) {
                ex.ToExceptionless().Submit();
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Failed to retrieve states", "Failed to retrieve states", true, false);
            }
            return(Ok(processingResult));
        }
Exemplo n.º 11
0
        public override void OnException(HttpActionExecutedContext context)
        {
            //Log Critical errors
            Debug.WriteLine(context.Exception);
            ServiceProcessingResult <string> result = new ServiceProcessingResult <string>
            {
                Error        = new ProcessingError(_message, _message, true),
                IsSuccessful = false,
                Data         = ""
            };
            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelcaseContractResolver()
            };

            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content      = new StringContent(JsonConvert.SerializeObject(result, Formatting.Indented, settings)),
                ReasonPhrase = "Critical Exception"
            });
        }
Exemplo n.º 12
0
        public async Task <ServiceProcessingResult <DataTable> > ExecuteReaderAsync(CommandType cmdType, string cmdText, params MySqlParameter[] commandParameters)
        {
            var processingResult = new ServiceProcessingResult <DataTable> {
                IsSuccessful = true
            };

            using (var connection = new MySqlConnection(_ConnectionString))
            {
                using (var command = new MySqlCommand(cmdText, connection))
                {
                    try
                    {
                        var dt = new DataTable();
                        command.CommandType = cmdType;
                        command.Parameters.Clear();
                        command.Parameters.AddRange(commandParameters);
                        connection.Open();

                        using (MySqlDataAdapter a = new MySqlDataAdapter(command))
                        {
                            a.Fill(dt);
                        }
                        processingResult.Data = dt;
                        return(processingResult);
                    }
                    catch (Exception ex)
                    {
                        processingResult.IsSuccessful = false;
                        ex.ToExceptionless().MarkAsCritical().AddObject(commandParameters).AddTags("Sql").Submit();
                        processingResult.Error = new ProcessingError("Error running ExecuteReaderAsync. Ex: " + ex.ToString(), "Error running ExecuteReaderAsync. Ex: " + ex.ToString(), false, false);
                        return(processingResult);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
        }
Exemplo n.º 13
0
        public async Task <IHttpActionResult> DuplicateOrderChk(OrdChkData model)
        {
            var processingResult = new ServiceProcessingResult <OrderData> {
                IsSuccessful = true
            };
            var parameters = new MySqlParameter[] {
                new MySqlParameter("@StudentLname", model.StudentLname),
                new MySqlParameter("@StudentFname", model.StudentFname),
                new MySqlParameter("@SchInvoiceNumber", model.ShcInvoicenumber)
            };
            var sqlText = @"
              SELECT OrderId,Studentfname,Studentlname,OrdDate From Orders Where StudentLname=@StudentLname and StudentFname=@StudentFname and SchInvoiceNumber=@SchInvoiceNumber";

            var sqlQuery       = new SQLQuery();
            var getOrderResult = await sqlQuery.ExecuteReaderAsync <OrderData>(CommandType.Text, sqlText, parameters);

            if (!getOrderResult.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error Checking for duplicate orders.", "Error checking for duplicate orders.", true, false);
                ExceptionlessClient.Default.CreateLog("Error Checking for duplicate orders.").Submit();
                return(Ok(processingResult));
            }
            var orderList = (List <OrderData>)getOrderResult.Data;

            if (orderList == null)
            {
                processingResult.Data = null;
            }
            else
            {
                processingResult.Data = orderList[0];
            }



            return(Ok(processingResult));
        }
Exemplo n.º 14
0
        public async Task <IHttpActionResult> GetBillingInfo(int orderid)

        {
            var processingResult = new ServiceProcessingResult <List <OrderBillingBindingModel> > {
                IsSuccessful = true
            };

            var sqlQuery = "SELECT distinct Schcode,Schname,Schinvoicenumber,Emailaddress,Studentfname,Studentlname,Sum(itemtotal) as Total FROM `temporders` o where Orderid =@OrderId";

            MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@OrderId", orderid) };
            var sqlQueryService         = new SQLQuery();
            var orderResult             = await sqlQueryService.ExecuteReaderAsync <OrderBillingBindingModel>(CommandType.Text, sqlQuery, parameters);

            if (!orderResult.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error retrieving billing information.", "Error retrieving billing information.", true, false);
                ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                return(Ok(processingResult));
            }

            if (orderResult.Data != null)
            {
                processingResult.Data         = (List <OrderBillingBindingModel>)orderResult.Data;
                processingResult.IsSuccessful = true;
            }
            else
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Failed to retrieve billing information.", "Failed to retrieve billing information.", true, false);
                ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, "Failed to retrieve billing information.", "Error");
            }



            return(Ok(processingResult));
        }
Exemplo n.º 15
0
        public async Task <IHttpActionResult> GetSchoolReceipt(string transid)
        {
            var processingResult = new ServiceProcessingResult <PaymentBindingModel> {
                IsSuccessful = true
            };

            //Get the order first thing to make sure we have it.

            try
            {
                var sqlQuery = "SELECT Schname,Schcode,PayerFname,PayerLname,Poamt,PayType,TransId,AuthCode,CustEmail,Ddate,OrderId from Payment  where transid=@Transid";
                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@Transid", transid) };
                var sqlQueryService         = new SQLQuery();
                var payResult = await sqlQueryService.ExecuteReaderAsync <PaymentBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!payResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError(payResult.Error.UserMessage, payResult.Error.UserMessage, true, false);
                    ExceptionlessClient.Default.CreateLog(typeof(OrderController).FullName, payResult.Error.UserMessage, "Error");
                    return(Ok(processingResult));
                }

                List <PaymentBindingModel> payments = (List <PaymentBindingModel>)payResult.Data;
                PaymentBindingModel        payment  = payments[0];//should only be one payment
                processingResult.Data = payment;
                return(Ok(processingResult));
            }catch (Exception ex)
            {
                ex.ToExceptionless()
                .SetMessage("Error retrieving payment for school receipt.");
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError(ex.Message, ex.Message, true, false);
                return(Ok(processingResult));
            }
        }
Exemplo n.º 16
0
        public async Task <IHttpActionResult> GetReceipt(string orderid)
        {
            var processingResult = new ServiceProcessingResult <ReceiptBindingModel> {
                IsSuccessful = true
            };
            //Get the order first thing to make sure we have it.
            ReceiptBindingModel Receipt = new ReceiptBindingModel();

            try
            {
                var sqlQuery = "SELECT Orders.Id,OrderId,PayType,Grade,BookType,Teacher,PersText1,Studentfname,Studentlname,Emailaddress,Schcode,ItemAmount,Itemqty,Schinvoicenumber,Orddate,ItemTotal,Schname,Yr,l1.caption as Caption1,l2.caption As Caption2,l3.caption As Caption3,l4.caption As Caption4 FROM Orders Left Join lookup l1 On l1.ivalue=Orders.icon1 Left Join lookup l2 on l2.ivalue=Orders.icon2 Left Join lookup l3 on l3.ivalue=Orders.icon3  Left Join lookup l4 on l4.ivalue=Orders.icon4  where orderid=@OrderId";
                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@OrderId", orderid) };
                var sqlQueryService         = new SQLQuery();
                var orderResult             = await sqlQueryService.ExecuteReaderAsync <OrderBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!orderResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("There was an error retrieving your order receipt.", "There was an error retrieving your order receipt.", true, false);
                    ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                    return(Ok(processingResult));
                }
                Receipt.Items = (List <OrderBindingModel>)orderResult.Data;

                MySqlParameter[] payParameters = new MySqlParameter[] { new MySqlParameter("@OrderId", orderid) };
                var sqlQueryService1           = new SQLQuery();
                sqlQuery = "Select Schcode,PayerFname,PayerLname,Poamt,PayType,TransId, AuthCode,CustEmail,Ddate,OrderId,Schname from Payment where orderid=@OrderId";
                var payResult = await sqlQueryService.ExecuteReaderAsync <PaymentBindingModel>(CommandType.Text, sqlQuery, payParameters);

                if (!payResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("There was an error retrieving your order receipt.", "There was an error retrieving your order receipt.", true, false);
                    ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                    return(Ok(processingResult));
                }
                List <PaymentBindingModel> payments = (List <PaymentBindingModel>)payResult.Data;
                PaymentBindingModel        payment  = payments[0];//should only be one payment
                Receipt.Schname       = payment.Schname;
                Receipt.Schcode       = payment.Schcode;
                Receipt.PayerFname    = payment.PayerFname;
                Receipt.PayerLname    = payment.PayerLname;
                Receipt.Payment       = payment.Poamt;
                Receipt.PayType       = payment.PayType;
                Receipt.TransId       = payment.TransId;
                Receipt.AuthCode      = payment.AuthCode;
                Receipt.OrderId       = payment.OrderId;
                Receipt.CustomerEmail = payment.CustEmail;
                Receipt.OrderDate     = payment.Ddate;
                Receipt.Payment       = payment.Poamt;
                processingResult.Data = Receipt;
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("There was an error retrieving your order receipt.", "There was an error retrieving your order receipt.", true, false);

                return(Ok(processingResult));
            }

            return(Ok(processingResult));
            //----------------------------------------------------------------------
        }
Exemplo n.º 17
0
        public async Task <IHttpActionResult> AuthNetSubmit(AuthNetBindingModel model)
        {
            var processingResult = new ServiceProcessingResult <List <OrderBindingModel> > {
                IsSuccessful = true
            };
            //Get the order first thing to make sure we have it.
            List <OrderBindingModel> Orders = new List <OrderBindingModel>();

            try
            {
                var sqlQuery = "SELECT Id,OrderId,PayType,Grade,BookType,Teacher,PersText1,Studentfname,Studentlname,Emailaddress,Schcode,ItemAmount,Itemqty,Schinvoicenumber,Orddate,ItemTotal,Schname,Yr,Icon1,Icon2,Icon3,Icon4,Josicon1,Josicon2,Josicon3,Josicon4 FROM temporders where orderid=@OrderId";

                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@OrderId", model.InvoiceNumber) };
                var sqlQueryService         = new SQLQuery();
                var orderResult             = await sqlQueryService.ExecuteReaderAsync <OrderBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!orderResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error retrieving order.", "Error retrieving order.", true, false);
                    ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                    return(Ok(processingResult));
                }
                if (orderResult.Data == null)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error retrieving order.", "Error retrieving order.", true, false);
                    ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                    return(Ok(processingResult));
                }


                Orders = (List <OrderBindingModel>)orderResult.Data;
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error retrieving order.", "Error retrieving order.", true, false);

                return(Ok(processingResult));
            }

            //----------------------------------------------------------------------

            var authNetService = new AuthNetService();
            var result         = await authNetService.SubmittAsync(model);

            if (!result.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error submiting payment to Authorzie.net", "Error submiting payment to Authorzie.net", true, false);
                ExceptionlessClient.Default.SubmitLog(typeof(OrderController).FullName, result.Error.UserHelp, "Error");
                return(Ok(processingResult));
            }
            AuthNetResponse AuthNetData = new AuthNetResponse();

            AuthNetData = result.Data;
            if (!AuthNetData.Approved)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Your payment to Authorized.net failed for the following reason:" + AuthNetData.Message, "Your payment to Authorized.net failed for the following reason:" + AuthNetData.Message, true, false);
                return(Ok(processingResult));
            }    //not approved
            else //Is Approved
            {
                foreach (var order in Orders)
                {
                    var sqlQuery1 = "INSERT INTO Orders (grade,booktype,teacher,perstext1,studentfname,studentlname,emailaddress,schcode,itemamount,itemqty,schinvoicenumber,orderid,orddate,paytype,itemtotal,schname,parentpayment,yr,icon1,icon2,icon3,icon4,josicon1,josicon2,josicon3,josicon4) VALUES(@grade,@booktype,@teacher,@perstext1,@studentfname,@studentlname,@emailaddress,@schcode,@itemamount,@itemqty,@schinvoicenumber,@orderid,@orddate,@paytype,@itemtotal,@schname,@parentpayment,@yr,@icon1,@icon2,@icon3,@icon4,@josicon1,@josicon2,@josicon3,@josicon4)";

                    MySqlParameter[] parameters = new MySqlParameter[] {
                        new MySqlParameter("@grade", order.Grade),
                        new MySqlParameter("@booktype", order.BookType),
                        new MySqlParameter("@teacher", order.Teacher),
                        new MySqlParameter("@perstext1", order.PersText1),
                        new MySqlParameter("@studentfname", order.Studentfname),
                        new MySqlParameter("@studentlname", order.Studentlname),
                        new MySqlParameter("@emailaddress", order.Emailaddress),
                        new MySqlParameter("@schcode", order.Schcode),
                        new MySqlParameter("@itemamount", order.ItemAmount),
                        new MySqlParameter("@itemqty", order.Itemqty),
                        new MySqlParameter("@schinvoicenumber", order.Schinvoicenumber),
                        new MySqlParameter("@orderid", order.OrderId),
                        new MySqlParameter("@orddate", order.Orddate),
                        new MySqlParameter("@paytype", order.PayType),
                        new MySqlParameter("@itemtotal", order.ItemTotal),
                        new MySqlParameter("@schname", order.Schname),
                        new MySqlParameter("@parentpayment", 1),
                        new MySqlParameter("@yr", order.Yr),
                        new MySqlParameter("@icon1", order.Icon1),
                        new MySqlParameter("@icon2", order.Icon2),
                        new MySqlParameter("@icon3", order.Icon3),
                        new MySqlParameter("@icon4", order.Icon4),
                        new MySqlParameter("@josicon1", order.Josicon1),
                        new MySqlParameter("@josicon2", order.Josicon2),
                        new MySqlParameter("@josicon3", order.Josicon3),
                        new MySqlParameter("@josicon4", order.Josicon4),
                    };
                    try
                    {
                        var sqlQueryService = new SQLQuery();
                        var orderResult     = await sqlQueryService.ExecuteNonQueryAsync(CommandType.Text, sqlQuery1, parameters);

                        if (!orderResult.IsSuccessful)
                        {
                            ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                            //create the mail message

                            MailMessage mail = new MailMessage();
                            //set the addresses
                            mail.From = new MailAddress(ConfigurationManager.AppSettings["FromAddr"]);
                            mail.To.Add("*****@*****.**");
                            //set the content
                            mail.Subject = "Mysql Error:Inserting Order " + order.Schname.ToString() + "(" + order.Schcode.ToString() + ")";
                            mail.Body    = "An error occured inserting a order record into the Mysql database server. The following data was not recorded in the order table.<br/>School Name:" + order.Schname +
                                           "<br/>Student Name:" + order.Studentfname + " " + order.Studentlname +
                                           "<br/>School Code:" + order.Schcode +
                                           "<br/>Order Id:" + model.InvoiceNumber +
                                           "<br/>Grade:" + order.Grade +
                                           "<br/>Teacher:" + order.Teacher +
                                           "<br/>Book Type:" + order.BookType +
                                           "<br/>EmailAddress:" + order.Emailaddress +
                                           "<br/>Perstext1:" + order.PersText1 +
                                           "<br/>Item Amount:" + order.ItemAmount +
                                           "<br/>Item Total:" + order.ItemTotal +
                                           "<br/>Item Qty:" + order.Itemqty +
                                           "<br/>icon1:" + order.Icon1 +
                                           "<br/>icon2:" + order.Icon2 +
                                           "<br/>icon3:" + order.Icon3 +
                                           "<br/>icon4:" + order.Icon4 +
                                           "<br/>Year:" + order.Yr +
                                           "<br/><br/>Mysql Exception Code:" + orderResult.Error.UserMessage;
                            mail.IsBodyHtml = true;
                            //send the message
                            SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["SmtpServer"]);
                            smtp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["smtpuser"], ConfigurationManager.AppSettings["smtppassword"]);
                            //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis 'only works on some serves
                            try
                            {
                                smtp.Send(mail);
                            }
                            catch (Exception ex)
                            {
                                //go on don't stop because email cant be sent.
                            }
                        }
                        if (orderResult.Data == 0)
                        {
                            ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, "Failed to insert an order", "Error");

                            MailMessage mail = new MailMessage();
                            //set the addresses
                            mail.From = new MailAddress(ConfigurationManager.AppSettings["FromAddr"]);
                            mail.To.Add("*****@*****.**");
                            //set the content
                            mail.Subject = "Mysql Error:Inserting Order " + order.Schname.ToString() + "(" + order.Schcode.ToString() + ")";
                            mail.Body    = "An error occured inserting a order record into the Mysql database server. The following data was not recorded in the order table.<br/>School Name:" + order.Schname +
                                           "<br/>Student Name:" + order.Studentfname + " " + order.Studentlname +
                                           "<br/>Order Id:" + model.InvoiceNumber +
                                           "<br/>School Code:" + order.Schcode +
                                           "<br/>Grade:" + order.Grade +
                                           "<br/>Teacher:" + order.Teacher +
                                           "<br/>Book Type:" + order.BookType +
                                           "<br/>EmailAddress:" + order.Emailaddress +
                                           "<br/>Perstext1:" + order.PersText1 +
                                           "<br/>Item Amount:" + order.ItemAmount +
                                           "<br/>Item Total:" + order.ItemTotal +
                                           "<br/>Item Qty:" + order.Itemqty +
                                           "<br/>icon1:" + order.Icon1 +
                                           "<br/>icon2:" + order.Icon2 +
                                           "<br/>icon3:" + order.Icon3 +
                                           "<br/>icon4:" + order.Icon4 +
                                           "<br/>Year:" + order.Yr +
                                           "<br/><br/>Mysql Exception Code:" + orderResult.Error.UserMessage;
                            mail.IsBodyHtml = true;
                            //send the message
                            SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["SmtpServer"]);
                            smtp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["smtpuser"], ConfigurationManager.AppSettings["smtppassword"]);
                            //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis 'only works on some serves
                            try
                            {
                                smtp.Send(mail);
                            }
                            catch (Exception ex)
                            {
                                //go on don't stop because email cant be sent.
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToExceptionless().Submit();
                    }
                }//endforeach
                 //,
                 //insert payment even if order failed
                try {
                    var sqlQuery = "INSERT INTO Payment (orderid,schname,schcode,custemail,ddate,poamt,paytype,ccnum,invno,parentpay,payerfname,payerlname,addr,city,state,zip,transid,authcode) VALUES(@orderid,@schname,@schcode,@custemail,@ddate,@poamt,@paytype,@ccnum,@invno,@parentpay,@payerfname,@payerlname,@addr,@city,@state,@zip,@transid,@authcode)";
                    MySqlParameter[] parameters1 = new MySqlParameter[] {
                        new MySqlParameter("@orderid", model.InvoiceNumber),
                        new MySqlParameter("@custemail", model.EmailAddress),
                        new MySqlParameter("@ddate", DateTime.Now),
                        new MySqlParameter("@poamt", model.Amount),
                        new MySqlParameter("@paytype", model.Method),
                        new MySqlParameter("@transid", AuthNetData.TransId),
                        new MySqlParameter("@authcode", AuthNetData.AuthCode),
                        new MySqlParameter("@ccnum", model.Cardnum == null?"":model.Cardnum.Substring(model.Cardnum.Length - 3)),
                        new MySqlParameter("@invno", Orders[0].Schinvoicenumber),
                        new MySqlParameter("@schname", Orders[0].Schname),
                        new MySqlParameter("@schcode", AuthNetData.Custid),
                        new MySqlParameter("@parentpay", 1),
                        new MySqlParameter("@payerfname", model.FirstName),
                        new MySqlParameter("@payerlname", model.LastName),
                        new MySqlParameter("@addr", model.Address),
                        new MySqlParameter("@city", model.City),
                        new MySqlParameter("@state", model.State.TrimEnd()),
                        new MySqlParameter("@zip", model.Zip)
                    };
                    var sqlQueryService1 = new SQLQuery();
                    var payResult        = await sqlQueryService1.ExecuteNonQueryAsync(CommandType.Text, sqlQuery, parameters1);

                    if (!payResult.IsSuccessful)
                    {
                        //fail it because we don't have the payment to create a receipt.
                        processingResult.IsSuccessful = false;
                        processingResult.Error        = new ProcessingError("Your payment was made but an error occurred creating your receipt. To obtain a receipt contact your school adviser with this tranasaction id:" + AuthNetData.TransId, "Your payment was made but an error occurred creating your receipt. To obtain a receipt contact your school adviser with this tranasaction id:" + AuthNetData.TransId, true, false);
                        ExceptionlessClient.Default.CreateLog(typeof(OrderController).FullName, "Error inserting  parent payment.", "Error").AddObject(model).AddObject(AuthNetData);
                        return(Ok(processingResult));
                    }
                    EmailReceipt(model.InvoiceNumber);
                }
                catch (Exception ex)
                {
                    ex.ToExceptionless()
                    .SetMessage("Error inserting payment.")
                    .AddTags("Insert Payment Error")
                    .AddObject(model)
                    .AddObject(AuthNetData)
                    .Submit();
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Your payment was made but an error occurred creating your receipt. To obtain a receipt contact your school adviser with this tranasaction id:" + AuthNetData.TransId, "Your payment was made but an error occurred creating your receipt. To obtain a receipt contact your school adviser with this tranasaction id:" + AuthNetData.TransId, true, false);

                    return(Ok(processingResult));
                }
            }// End Approved
            return(Ok(processingResult));
        }
Exemplo n.º 18
0
        public async Task <IHttpActionResult> SchoolAuthNetSubmit(AuthNetBindingModel model)
        {
            var processingResult = new ServiceProcessingResult <string> {
                IsSuccessful = true
            };
            var authNetService = new AuthNetService();
            var result         = await authNetService.SubmittAsync(model);

            if (!result.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Error submiting payment to Authorzie.net", "Error submiting payment to Authorzie.net", true, false);
                ExceptionlessClient.Default.SubmitLog(typeof(OrderController).FullName, result.Error.UserHelp, "Error");
                return(Ok(processingResult));
            }
            AuthNetResponse AuthNetData = new AuthNetResponse();

            AuthNetData = result.Data;
            if (!AuthNetData.Approved)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Your payment to Authorized.net failed for the following reason:" + AuthNetData.Message, "Your payment to Authorized.net failed for the following reason:" + AuthNetData.Message, true, false);
                return(Ok(processingResult));
            }
            var    sqlQuery = "INSERT INTO Payment (schcode,schname,custemail,ddate,poamt,paytype,ccnum,invno,parentpay,payerfname,payerlname,transid,authcode) VALUES(@schcode,@schname,@custemail,@ddate,@poamt,@paytype,@ccnum,@invno,@parentpay,@payerfname,@payerlname,@transid,@authcode)";
            string fname    = "";
            string lname    = "";

            if (!String.IsNullOrEmpty(model.BankAccName))
            {
                fname = model.BankAccName.Substring(0, model.BankAccName.IndexOf(" ") - 1);
                lname = model.BankAccName.Substring(model.BankAccName.IndexOf(" ") + 1);
            }
            else
            {
                fname = model.FirstName;
                lname = model.LastName;
            }
            MySqlParameter[] parameters = new MySqlParameter[] {
                new MySqlParameter("@custemail", model.EmailAddress),
                new MySqlParameter("@ddate", DateTime.Now),
                new MySqlParameter("@poamt", model.Amount),
                new MySqlParameter("@payerfname", fname),
                new MySqlParameter("@payerlname", lname),
                new MySqlParameter("@paytype", model.Method),
                new MySqlParameter("@transid", AuthNetData.TransId),
                new MySqlParameter("@authcode", AuthNetData.AuthCode),
                new MySqlParameter("@ccnum", model.Cardnum == null?"":model.Cardnum.Substring(model.Cardnum.Length - 3)),
                new MySqlParameter("@invno", model.InvoiceNumber),
                new MySqlParameter("@schcode", AuthNetData.Custid),
                new MySqlParameter("@schname", model.Schname),
                new MySqlParameter("@parentpay", "0"),
            };
            var sqlQueryService = new SQLQuery();
            var payResult       = await sqlQueryService.ExecuteNonQueryAsync(CommandType.Text, sqlQuery, parameters);

            if (!payResult.IsSuccessful)
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Your payment was made but an error occurred creating your receipt. To obtain a receipt contact Memory Book with this tranasaction id:" + AuthNetData.TransId, "Your payment was made but an error occurred creating your receipt. To obtain a receipt contact Memory Book with this tranasaction id:" + AuthNetData.TransId, true, false);
                ExceptionlessClient.Default.CreateLog(typeof(OrderController).FullName, "Error inserting school payment.", "Error").AddObject(model).AddObject(AuthNetData);
                return(Ok(processingResult));
            }
            EmailSchoolReceipt(AuthNetData.TransId);


            processingResult.Data = AuthNetData.TransId;
            return(Ok(processingResult));
        }
Exemplo n.º 19
0
        public async Task <IHttpActionResult> testData()
        {
            var processingResult = new ServiceProcessingResult <List <TestBindingModel> > {
                IsSuccessful = true
            };

            if (!RequestIsAuthorized())
            {
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Not authorized.", "Not authorized.", false);
                return(Ok(processingResult));
            }

            //using (OleDbConnection Conn = new OleDbConnection("Provider = VFPOLEDB.1; Data Source = M:\\MBC5"))
            using (OleDbConnection Conn = new OleDbConnection("Provider = VFPOLEDB.1; Data Source = E:\\MbcData\\MBC5"))
            {
                using (OleDbCommand cmd = new OleDbCommand("select Top(10) CUST.SCHNAME,CUST.SCHCODE from CUST where upper(CUST.SCHNAME) like 'A%' ORDER BY Schname", Conn))
                {
                    try
                    {
                        var dt = new DataTable();
                        cmd.CommandType = CommandType.Text;
                        Conn.Open();
                        using (OleDbDataAdapter a = new OleDbDataAdapter(cmd))
                        {
                            a.Fill(dt);
                            List <TestBindingModel> lCust = new List <TestBindingModel>();
                            foreach (DataRow row in dt.Rows)
                            {
                                var rec = new TestBindingModel()
                                {
                                    schcode = row["schcode"].ToString().Trim(),
                                    schname = row["schname"].ToString().Trim()
                                };
                                lCust.Add(rec);
                            }
                            processingResult.Data = lCust;
                        }
                    }
                    catch (Exception ex)
                    {
                        processingResult.IsSuccessful = false;
                        ex.ToExceptionless()
                        .SetMessage("Error running TestData")
                        .AddTags("Test Function")
                        .AddObject(cmd)
                        .MarkAsCritical()
                        .Submit();
                        processingResult.Error = new ProcessingError(ex.Message, ex.Message, true, false);
                        return(Ok(processingResult));
                    }
                    finally
                    {
                        Conn.Close();
                    }
                }
            }



            return(Ok(processingResult));
        }
Exemplo n.º 20
0
        public async Task <ServiceProcessingResult <AuthNetResponse> > SubmittAsync(AuthNetBindingModel model)


        {
            var result = new ServiceProcessingResult <AuthNetResponse> {
                IsSuccessful = true
            };
            //  ' By default, this sample code is designed to post to our test server for
            //  ' developer accounts: https://test.authorize.net/gateway/transact.dll
            //  ' for real accounts (even in test mode), please make sure that you are
            //  'posting to: https://secure.authorize.net/gateway/transact.dll
            //' post_url = "https://secure.authorize.net/gateway/transact.dll"
            string post_url = ConfigurationManager.AppSettings["AuthUrl"].ToString();
            Dictionary <string, string> post_values = new Dictionary <string, string>();
            string login = ConfigurationManager.AppSettings["mbc" + "ApiLogin"].ToString();//need variable to tell what site to use. should come in post
            string Key   = ConfigurationManager.AppSettings["mbc" + "TransactionKey"].ToString();
            string test  = ConfigurationManager.AppSettings["GatewayTest"].ToString();


            //post_values.Add("x_test_request", ConfigurationManager.AppSettings("GatewayTest")) /*use this for submissions to live site only-----------------------------------------------------------------------------------------------------------------*/
            post_values.Add("x_test_request", test);
            post_values.Add("x_version", "3.1");
            post_values.Add("x_login", login);
            post_values.Add("x_tran_key", Key);
            post_values.Add("x_delim_data", "TRUE");
            post_values.Add("x_delim_char", "|");
            post_values.Add("x_relay_response_array", "FALSE");
            post_values.Add("x_type", "AUTH_CAPTURE"); /*' request.TransType AUTH_CAPTURE,AUTH_ONLY,PRIOR_AUTH_CAPTURE,CREDIT,VOID ect.*/
            post_values.Add("x_method", model.Method); /* 'CC,ECHECK*/
            post_values.Add("x_echeck_type", "WEB");   /* 'web*/
            post_values.Add("x_card_num", model.Cardnum);
            post_values.Add("x_exp_date", model.ExpirationDate);
            post_values.Add("x_card_code", model.CardCode);
            post_values.Add("x_recurring_billing", "FALSE");        /*' we don't use this so is always false*/
            post_values.Add("x_bank_acct_name", model.BankAccName); //customer name
            post_values.Add("x_bank_name", model.BankName);
            post_values.Add("x_bank_acct_type", model.BankAccType); /*'savings,checking,businesschecking*/
            post_values.Add("x_bank_aba_code", model.BankAbaCode);
            post_values.Add("x_bank_acct_num", model.BankAccountNumber);
            post_values.Add("x_amount", model.Amount);
            post_values.Add("x_description", "");
            post_values.Add("x_cust_id", model.CustId);
            post_values.Add("x_first_name", model.FirstName);
            post_values.Add("x_last_name", model.LastName);
            post_values.Add("x_address", model.Address);
            post_values.Add("x_state", model.State);
            post_values.Add("x_ city", model.City);
            post_values.Add("x_zip", model.Zip);
            post_values.Add("x_invoice_num", model.InvoiceNumber);
            post_values.Add("x_email", model.EmailAddress);
            post_values.Add("x_duplicate_window", "420");/* '7 minutes*/

            //    ' Additional fields can be added here as outlined in the AIM integration
            //' guide at: http://developer.authorize.net

            //' This section takes the input fields and converts them to the proper format
            //' for an http post.  For example: "x_login=username&x_tran_key=a1B2c3D4"
            string post_string = "";

            foreach (KeyValuePair <string, string> field in post_values)
            {
                post_string += field.Key + "=" + HttpUtility.UrlEncode(field.Value) + "&";
            }

            post_string = post_string.Substring(0, post_string.Length - 1);
            //' create an HttpWebRequest object to communicate with Authorize.net
            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(post_url);

            objRequest.Method        = "POST";
            objRequest.ContentLength = post_string.Length;
            objRequest.ContentType   = "application/x-www-form-urlencoded";
            //' post data is sent as a stream
            StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream());

            myWriter.Write(post_string);
            myWriter.Close();
            // returned values are returned as a stream, then read into a string


            HttpWebResponse objResponse    = (HttpWebResponse)objRequest.GetResponse();
            StreamReader    responseStream = new StreamReader(objResponse.GetResponseStream());
            string          post_response  = responseStream.ReadToEnd();

            responseStream.Close();


            // the response_array string is broken into an array


            String[] response_array = post_response.Split('|');


            AuthNetResponse Returnresponse_array = new AuthNetResponse();

            try
            {
                //Returnresponse_array.Approved = Returnresponse_array.GetText(response_array(1)) '1,2,3,4 approved,declined,error,held for review
                bool approvedret = false;
                switch (response_array[0])
                {
                case "1":
                    approvedret = true;
                    break;

                default:
                    approvedret = false;
                    break;
                }
                Returnresponse_array.Approved = approvedret;
                Returnresponse_array.Message  = response_array[3];
                Returnresponse_array.AuthCode = response_array[4];
                Returnresponse_array.TransId  = response_array[6];
                string r  = response_array[7];
                string rr = response_array[5];
                Returnresponse_array.Amount          = response_array[9];
                Returnresponse_array.Method          = response_array[10];
                Returnresponse_array.TransActionType = response_array[11];
                Returnresponse_array.Custid          = response_array[12];
                Returnresponse_array.Email           = response_array[23];
                Returnresponse_array.CardNum         = response_array[50];
                Returnresponse_array.CardType        = response_array[51];
                //will fail if submission faisl and there are not enough elements
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                result.IsSuccessful = false;
                result.Error        = new ProcessingError(ex.Message, ex.Message, true, false);
                return(result);
            }

            result.IsSuccessful = true;
            result.Data         = Returnresponse_array;
            return(result);
        }
Exemplo n.º 21
0
        public async Task <IHttpActionResult> InvoiceInit(string invNumber)
        {
            var processingResult = new ServiceProcessingResult <InvoiceInitBindingModel> {
                IsSuccessful = true
            };

            try
            {
                //var sqlQuery = @"SELECT I.schcode, I.invno, D.teacher, D.id FROM invoiceinfo I LEFT JOIN dropdowninfo D ON I.schcode=D.schcode  WHERE I.invno=@InvNumber ORDER BY D.teacher";
                var sqlQuery = @"SELECT I.schcode, I.invno, D.teacher,D.grade, D.id FROM invoiceinfo I INNER JOIN dropdowninfo D ON I.schcode=D.schcode  WHERE I.invno=@InvNumber ORDER BY D.teacher";
                MySqlParameter[] parameters       = new MySqlParameter[] { new MySqlParameter("@InvNumber", invNumber) };
                var sqlQueryService               = new SQLQuery();
                var getInvoiceTeacherLookupResult = await sqlQueryService.ExecuteReaderAsync <InvoiceTeacherLookupBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!getInvoiceTeacherLookupResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting teachers", "Error getting teachers", true, false);
                    ExceptionlessClient.Default.SubmitLog("Error getting teachers");
                    return(Ok(processingResult));
                }

                //sqlQuery = @"SELECT I.schcode, D.grade, D.id FROM invoiceinfo I LEFT JOIN dropdowninfo D ON I.schcode = D.schcode  WHERE I.invno=@InvNumber ORDER BY D.grade";
                sqlQuery   = @"SELECT DISTINCT I.schcode, D.grade FROM invoiceinfo I INNER JOIN dropdowninfo D ON I.schcode = D.schcode  WHERE I.invno=@InvNumber ORDER BY D.grade";
                parameters = new MySqlParameter[] { new MySqlParameter("@InvNumber", invNumber) };
                var getInvoiceGradeLookupResult = await sqlQueryService.ExecuteReaderAsync <InvoiceGradeLookupBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!getInvoiceGradeLookupResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting grades", "Error getting grades", true, false);
                    ExceptionlessClient.Default.SubmitLog("Error getting grades");
                    return(Ok(processingResult));
                }

                sqlQuery = @"SELECT id, cvalue, isortorder, caption, ivalue, csortorder FROM Lookup";
                var getInvoiceIconLookupResult = await sqlQueryService.ExecuteReaderAsync <InvoiceIconLookupBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!getInvoiceIconLookupResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting icons", "Error getting icons", true, false);
                    ExceptionlessClient.Default.SubmitLog("Error getting icons");
                    return(Ok(processingResult));
                }

                sqlQuery   = @"SELECT I.schname AS schoolname, I.* FROM invoiceinfo I WHERE I.invno=@InvNumber";
                parameters = new MySqlParameter[] { new MySqlParameter("@InvNumber", invNumber) };
                var getSchoolNameResult = await sqlQueryService.ExecuteReaderAsync <InvoiceSchoolNameBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!getSchoolNameResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting school name", "Error getting school name", true, false);
                    ExceptionlessClient.Default.SubmitLog("Error getting school name");
                    return(Ok(processingResult));
                }


                processingResult.IsSuccessful = true;

                var     invoiceInfoList = (List <InvoiceSchoolNameBindingModel>)getSchoolNameResult.Data;
                var     invoiceInfo = invoiceInfoList[0];
                decimal basicinvamt, iconamt, inkpersamt, foilpersamt, picpersamt, foiltxtamt, inktxtamt, luvlineamt, fulladlineamt, halfadlineamt, quarteradlineamt, eighthadlineamt;
                decimal.TryParse(invoiceInfo.basicinvamt, out basicinvamt);
                processingResult.Data             = new InvoiceInitBindingModel();
                processingResult.Data.SchCode     = invoiceInfo.schcode;
                processingResult.Data.Invno       = invoiceInfo.invno;
                processingResult.Data.BasicOnly   = invoiceInfo.basiconly;
                processingResult.Data.BasicInvAmt = decimal.TryParse(invoiceInfo.basicinvamt, out basicinvamt) ? basicinvamt :0; Convert.ToDecimal(invoiceInfo.basicinvamt);
                processingResult.Data.InkPers     = invoiceInfo.inkpers;
                processingResult.Data.InkPersAmt  = decimal.TryParse(invoiceInfo.inkpersamt, out inkpersamt) ? inkpersamt : 0;
                processingResult.Data.FoilPers    = invoiceInfo.foilpers;
                processingResult.Data.FoilPersAmt = decimal.TryParse(invoiceInfo.foilpersamt, out foilpersamt) ? foilpersamt : 0;
                processingResult.Data.IconAmt     = invoiceInfo.iconamt;
                processingResult.Data.PicPers     = invoiceInfo.picpers;
                processingResult.Data.PicPersAmt  = decimal.TryParse(invoiceInfo.picpersamt, out picpersamt) ? picpersamt : 0;
                processingResult.Data.FoilTxtAmt  = decimal.TryParse(invoiceInfo.foiltxtamt, out foiltxtamt) ? foiltxtamt : 0;
                processingResult.Data.FoilTxt     = invoiceInfo.foiltxt;
                processingResult.Data.InkText     = invoiceInfo.inktxt;
                processingResult.Data.InkTextAmt  = decimal.TryParse(invoiceInfo.inktxtamt, out inktxtamt) ? inktxtamt : 0;
                processingResult.Data.LuvLines    = invoiceInfo.luvlines;
                processingResult.Data.LuvLineAmt  = decimal.TryParse(invoiceInfo.luvlineamt, out luvlineamt) ? luvlineamt : 0;
                processingResult.Data.AdLine      = invoiceInfo.adline;

                processingResult.Data.FullAdlineAmt   = decimal.TryParse(invoiceInfo.fulladlineamt, out fulladlineamt) ? fulladlineamt : 0;
                processingResult.Data.HalfAdlineAmt   = decimal.TryParse(invoiceInfo.halfadlineamt, out halfadlineamt) ? halfadlineamt : 0;
                processingResult.Data.QuaterAdlineAmt = decimal.TryParse(invoiceInfo.quarteradlineamt, out quarteradlineamt) ? quarteradlineamt : 0;
                processingResult.Data.EightAdlineAmt  = decimal.TryParse(invoiceInfo.eighthadlineamt, out eighthadlineamt) ? eighthadlineamt : 0;
                processingResult.Data.OnlineCuto      = invoiceInfo.onlinecuto;
                processingResult.Data.Adcuto          = invoiceInfo.adcuto;
                processingResult.Data.schoolname      = invoiceInfo.schoolname;


                processingResult.Data.Teachers = (List <InvoiceTeacherLookupBindingModel>)getInvoiceTeacherLookupResult.Data;
                processingResult.Data.Grades   = (List <InvoiceGradeLookupBindingModel>)getInvoiceGradeLookupResult.Data;
                processingResult.Data.Icons    = (List <InvoiceIconLookupBindingModel>)getInvoiceIconLookupResult.Data;
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
            }
            return(Ok(processingResult));
        }
Exemplo n.º 22
0
        public async Task <IHttpActionResult> GetOrder(int orderid)
        {
            var processingResult = new ServiceProcessingResult <List <OrderBindingModel> > {
                IsSuccessful = true
            };

            try {
                var sqlQuery = "SELECT * FROM temporders where orderid=@OrderId";
                MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("@OrderId", orderid) };
                var sqlQueryService         = new SQLQuery();
                var orderResult             = await sqlQueryService.ExecuteReaderAsync(CommandType.Text, sqlQuery, parameters);

                if (!orderResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error retrieving order.", "Error retrieving order.", true, false);
                    ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, orderResult.Error.UserMessage, "Error");
                    return(Ok(processingResult));
                }

                if (orderResult.Data.Rows.Count > 0)
                {
                    List <OrderBindingModel> Orders = new List <OrderBindingModel>();
                    foreach (DataRow row in orderResult.Data.Rows)
                    {
                        var aa = row["icon1"];
                        var b  = aa.GetType();
                        OrderBindingModel order = new OrderBindingModel()
                        {
                            Id               = (UInt32)row["id"],      // will not be null primary key of temporders
                            OrderId          = (UInt32)row["orderid"], //if fail because null good, don't want a order with out an id.
                            BookType         = row["booktype"].ToString(),
                            Teacher          = row["teacher"].ToString(),
                            PersText1        = row["perstext1"].ToString(),
                            Studentfname     = row["studentfname"].ToString(),
                            Studentlname     = row["studentlname"].ToString(),
                            Emailaddress     = row["emailaddress"].ToString(),
                            Schcode          = row["schcode"].ToString(),
                            ItemAmount       = row["itemamount"] == DBNull.Value ? 0 : (decimal)row["itemamount"],
                            Itemqty          = row["itemqty"] == DBNull.Value ? 0 :(UInt32)row["itemqty"],
                            Schinvoicenumber = row["schinvoicenumber"] == DBNull.Value? 0:(UInt32)row["schinvoicenumber"],
                            Orddate          = row["orddate"] == DBNull.Value ? DateTime.Now : (DateTime)row["orddate"],
                            ItemTotal        = row["itemtotal"] == DBNull.Value ? 0 : (decimal)row["itemtotal"],
                            Schname          = row["schname"].ToString(),
                            Yr               = row["yr"].ToString(),
                            Icon1            = row["icon1"] == DBNull.Value? 0:(UInt32)row["icon1"],
                            Icon2            = row["icon1"] == DBNull.Value? 0:(UInt32)row["icon2"],
                            Icon3            = row["icon1"] == DBNull.Value? 0:(UInt32)row["icon3"],
                            Icon4            = row["icon1"] == DBNull.Value? 0:(UInt32)row["icon4"],
                            Josicon1         = row["josicon1"].ToString(),
                            Josicon2         = row["josicon2"].ToString(),
                            Josicon3         = row["josicon3"].ToString(),
                            Josicon4         = row["josicon4"].ToString()
                        };
                        Orders.Add(order);
                    }
                    processingResult.Data         = Orders;
                    processingResult.IsSuccessful = true;
                }
                else
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Failed to retrieve order", "Failed to retrieve order", true, false);
                    ExceptionlessClient.Default.SubmitLog(typeof(TempOrderController).FullName, "Order was not found.", "Error");
                }
            } catch (Exception ex) {
                ex.ToExceptionless().Submit();
                processingResult.IsSuccessful = false;
                processingResult.Error        = new ProcessingError("Failed to retrieve order", "Failed to retrieve order.", true, false);
            }
            return(Ok(processingResult));
        }
Exemplo n.º 23
0
        public async Task <IHttpActionResult> Checkout(CheckoutRequestBindingModel model)
        {
            var processingResult = new ServiceProcessingResult <int> {
                IsSuccessful = true
            };

            //GetOrderCode here
            var currentRow = 0;
            var OrderID    = 0;

            //Get New Order Code Here
            var sqlText = @"
                SELECT value FROM sys
            ";

            var sqlQuery         = new SQLQuery();
            var getOrderIDResult = await sqlQuery.ExecuteReaderAsync <GetOrderIDRequest>(CommandType.Text, sqlText);

            var orderidlist = (List <GetOrderIDRequest>)getOrderIDResult.Data;

            OrderID = Convert.ToInt32(orderidlist[0].value) + 1;

            MySqlParameter[] parameters = new MySqlParameter[] {
                new MySqlParameter("@value", OrderID),
            };
            sqlText = @"UPDATE sys SET value=@value";

            var updateOrderIDResult = await sqlQuery.ExecuteNonQueryAsync(CommandType.Text, sqlText, parameters);


            foreach (var row in model.Items)
            {
                currentRow += 1;
                try {
                    var pertext = "";
                    if (row.Data.PersonalizedText == "" || row.Data.PersonalizedText == null)
                    {
                        pertext = "Not Available";
                    }
                    else
                    {
                        pertext = row.Data.PersonalizedText;
                    }

                    int?icon1 = null;
                    int?icon2 = null;
                    int?icon3 = null;
                    int?icon4 = null;

                    string josicon1 = null;
                    string josicon2 = null;
                    string josicon3 = null;
                    string josicon4 = null;

                    if (row.Data.Icon1 != null)
                    {
                        icon1 = Convert.ToInt32(row.Data.Icon1.Ivalue); josicon1 = row.Data.Icon1.Cvalue;
                    }
                    if (row.Data.Icon2 != null)
                    {
                        icon2 = Convert.ToInt32(row.Data.Icon2.Ivalue); josicon2 = row.Data.Icon2.Cvalue;
                    }
                    if (row.Data.Icon3 != null)
                    {
                        icon3 = Convert.ToInt32(row.Data.Icon3.Ivalue); josicon3 = row.Data.Icon3.Cvalue;
                    }
                    if (row.Data.Icon4 != null)
                    {
                        icon4 = Convert.ToInt32(row.Data.Icon4.Ivalue); josicon4 = row.Data.Icon4.Cvalue;
                    }

                    Decimal amount = 0;
                    Decimal total  = 0;
                    try {
                        //switched
                        total  = Convert.ToDecimal(row.Total);
                        amount = Convert.ToDecimal(row.Price);
                    } catch (Exception ex) { }


                    parameters = new MySqlParameter[] {
                        new MySqlParameter("@grade", row.Data.Grade),
                        new MySqlParameter("@booktype", row.Data.YearbookType),
                        new MySqlParameter("@teacher", row.Data.Teacher),
                        new MySqlParameter("@perstext", pertext),
                        new MySqlParameter("@studentfname", row.Data.StudentFirstName),
                        new MySqlParameter("@emailaddress", row.Data.Email),
                        new MySqlParameter("@schcode", row.Data.SchCode),
                        new MySqlParameter("@itemamount", amount),
                        new MySqlParameter("@itemqty", row.Quantity),
                        new MySqlParameter("@schinvoicenumber", row.Data.InvoiceNumber),
                        new MySqlParameter("@orderid", OrderID),
                        new MySqlParameter("@orddate", DateTime.Now),
                        new MySqlParameter("@paytype", "CC"),
                        new MySqlParameter("@itemtotal", total),
                        new MySqlParameter("@studentlname", row.Data.StudentLastName),
                        new MySqlParameter("@schname", row.Data.SchoolName),
                        new MySqlParameter("@parentpayment", row.Data.ParentPayment),
                        new MySqlParameter("@yr", row.Data.Year.Substring(4 - 2)),
                        new MySqlParameter("@sname", row.Data.SchoolName),
                        new MySqlParameter {
                            ParameterName = "@icon1",
                            DbType        = DbType.Int32,
                            Value         = icon1
                        },
                        new MySqlParameter {
                            ParameterName = "@icon2",
                            DbType        = DbType.Int32,
                            Value         = icon2
                        },
                        new MySqlParameter {
                            ParameterName = "@icon3",
                            DbType        = DbType.Int32,
                            Value         = icon3
                        },
                        new MySqlParameter {
                            ParameterName = "@icon4",
                            DbType        = DbType.Int32,
                            Value         = icon4
                        },
                        new MySqlParameter {
                            ParameterName = "@josicon1",
                            Value         = josicon1
                        },
                        new MySqlParameter {
                            ParameterName = "@josicon2",
                            Value         = josicon2
                        },
                        new MySqlParameter {
                            ParameterName = "@josicon3",
                            Value         = josicon3
                        },
                        new MySqlParameter {
                            ParameterName = "@josicon4",
                            Value         = josicon4
                        }
                    };

                    sqlText = @"
                    INSERT INTO TempOrders (
                        grade, booktype, teacher,
                        perstext1, studentfname,
                        emailaddress, schcode, itemamount,
                        itemqty, schinvoicenumber, orderid,
                        orddate, paytype, itemtotal,
                        studentlname, schname, parentpayment,
                        yr, sname,
                        icon1,icon2,icon3,icon4,
                        josicon1,josicon2,josicon3,josicon4
                    ) VALUES (
                        @grade, @booktype, @teacher,
                        @perstext, @studentfname,
                        @emailaddress, @schcode, @itemamount,
                        @itemqty, @schinvoicenumber, @orderid,
                        @orddate, @paytype, @itemtotal,
                        @studentlname, @schname, @parentpayment,
                        @yr, @sname,
                        @icon1,@icon2,@icon3,@icon4,
                        @josicon1,@josicon2,@josicon3,@josicon4
                    )
                ";

                    var saveOrderResult = await sqlQuery.ExecuteNonQueryAsync(CommandType.Text, sqlText, parameters);

                    if (!saveOrderResult.IsSuccessful)
                    {
                        processingResult.IsSuccessful = false;
                        processingResult.Error        = new ProcessingError("Error inserting temp order into database", "Error inserting temp order into database", false, false);

                        ExceptionlessClient.Default.SubmitLog("Error inserting row into temp orders table.", "Fatal");

                        return(Ok(processingResult));
                    }
                } catch (Exception ex) {
                }
            }

            processingResult.Data = OrderID;

            return(Ok(processingResult));
        }
Exemplo n.º 24
0
        public async Task <IHttpActionResult> InvoiceInit(string invNumber)
        {
            var processingResult = new ServiceProcessingResult <InvoiceInitBindingModel> {
                IsSuccessful = true
            };

            try
            {
                var sqlQuery = @"SELECT I.schcode, I.invno, D.teacher, D.id FROM invoiceinfo I LEFT JOIN dropdowninfo D ON I.schcode=D.schcode  WHERE I.invno=@InvNumber";
                MySqlParameter[] parameters       = new MySqlParameter[] { new MySqlParameter("@InvNumber", invNumber) };
                var sqlQueryService               = new SQLQuery();
                var getInvoiceTeacherLookupResult = await sqlQueryService.ExecuteReaderAsync <InvoiceTeacherLookupBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!getInvoiceTeacherLookupResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting teachers", "Error getting teachers", true, false);
                    ExceptionlessClient.Default.SubmitLog("Error getting teachers");
                    return(Ok(processingResult));
                }

                sqlQuery   = @"SELECT I.schcode, D.grade, D.id FROM invoiceinfo I LEFT JOIN dropdowninfo D ON I.schcode = D.schcode  WHERE I.invno=@InvNumber";
                parameters = new MySqlParameter[] { new MySqlParameter("@InvNumber", invNumber) };
                var getInvoiceGradeLookupResult = await sqlQueryService.ExecuteReaderAsync <InvoiceGradeLookupBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!getInvoiceGradeLookupResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting grades", "Error getting grades", true, false);
                    ExceptionlessClient.Default.SubmitLog("Error getting grades");
                    return(Ok(processingResult));
                }

                sqlQuery = @"SELECT id, cvalue, isortorder, caption, ivalue, csortorder FROM Lookup";
                var getInvoiceIconLookupResult = await sqlQueryService.ExecuteReaderAsync <InvoiceIconLookupBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!getInvoiceIconLookupResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting icons", "Error getting icons", true, false);
                    ExceptionlessClient.Default.SubmitLog("Error getting icons");
                    return(Ok(processingResult));
                }

                sqlQuery   = @"SELECT schname AS schoolname FROM invoiceinfo WHERE invno=@InvNumber";
                parameters = new MySqlParameter[] { new MySqlParameter("@InvNumber", invNumber) };
                var getSchoolNameResult = await sqlQueryService.ExecuteReaderAsync <InvoiceSchoolNameBindingModel>(CommandType.Text, sqlQuery, parameters);

                if (!getSchoolNameResult.IsSuccessful)
                {
                    processingResult.IsSuccessful = false;
                    processingResult.Error        = new ProcessingError("Error getting school name", "Error getting school name", true, false);
                    ExceptionlessClient.Default.SubmitLog("Error getting school name");
                    return(Ok(processingResult));
                }


                processingResult.IsSuccessful = true;

                var schoolname = (List <InvoiceSchoolNameBindingModel>)getSchoolNameResult.Data;

                processingResult.Data            = new InvoiceInitBindingModel();
                processingResult.Data.SchoolName = schoolname[0].schoolname;
                processingResult.Data.Teachers   = (List <InvoiceTeacherLookupBindingModel>)getInvoiceTeacherLookupResult.Data;
                processingResult.Data.Grades     = (List <InvoiceGradeLookupBindingModel>)getInvoiceGradeLookupResult.Data;
                processingResult.Data.Icons      = (List <InvoiceIconLookupBindingModel>)getInvoiceIconLookupResult.Data;
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
            }
            return(Ok(processingResult));
        }