public HttpResponseMessage AddItemToGuide([FromBody] OrderGuides.OrderGuide orderguide)
        {
            try
            {
                Logger.WriteLine("Adding item to Order Guide..");
                SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConnection"].ConnectionString);

                using (connect)
                {
                    SqlCommand cmd = new SqlCommand("INSERT INTO masterOrderGuide (prodCode, unit_id, group_id, qty, itemComment, sortOrder) VALUES (@prodCode, @unit_id, @group_id, @qty, @itemComment, @sortOrder)", connect);
                    cmd.Parameters.AddWithValue("@prodCode", orderguide.Code);
                    cmd.Parameters.AddWithValue("@unit_id", orderguide.Unit);
                    cmd.Parameters.AddWithValue("@group_id", orderguide.groupID);
                    cmd.Parameters.AddWithValue("@qty", orderguide.Qty);
                    cmd.Parameters.AddWithValue("@itemComment", orderguide.Comment);
                    cmd.Parameters.AddWithValue("@sortOrder", orderguide.sortOrder);
                    connect.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Exception @ AddItemToGuide() : " + ex.Message);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }

            var message = Request.CreateResponse(HttpStatusCode.OK);

            message.Headers.Location = new Uri(Request.RequestUri.ToString());
            Logger.WriteLine("Adding Item to Guide Successful. Item : " + orderguide.Code.ToString() + ", Group ID : " + orderguide.groupID.ToString());
            return(message);
        }
        public HttpResponseMessage DeleteItemFromGuide([FromBody] OrderGuides.OrderGuide orderguide)
        {
            try
            {
                SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConnection"].ConnectionString);

                using (connect)
                {
                    SqlCommand cmd = new SqlCommand("Delete From masterOrderGuide Where group_id = @groupID AND (prodCode = @prodCode AND unit_id = @unit_id)", connect);
                    cmd.Parameters.AddWithValue("@prodCode", orderguide.Code);
                    cmd.Parameters.AddWithValue("@unit_id", orderguide.Unit);
                    cmd.Parameters.AddWithValue("@groupID", orderguide.groupID);
                    connect.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Exception @ DeleteItemFromGuide() : " + ex.Message);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }

            var message = Request.CreateResponse(HttpStatusCode.OK);

            message.Headers.Location = new Uri(Request.RequestUri.ToString());
            Logger.WriteLine("Item Deleted from Guide. Item : " + orderguide.Code.ToString() + ", Unit : " + orderguide.Unit + " , Group ID : " + orderguide.groupID.ToString());
            return(message);
        }
        public HttpResponseMessage GetSessionCart()
        {
            Logger.WriteLine("Fetching Session Cart....");
            string custCode    = login.GetLoggedInUser.m_sessionCustomer;
            string orderNumber = login.GetLoggedInUser.m_sessionOrderNum;
            int?   priceLevel  = login.GetLoggedInUser.m_priceLevel;

            List <OrderGuides.OrderGuide> OrderGuides = new List <OrderGuides.OrderGuide>();

            try
            {
                SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConnection"].ConnectionString);
                using (connect)
                {
                    SqlCommand cmd = new SqlCommand();

                    if (login.GetLoggedInUser.m_showPrices > 0)
                    {
                        cmd = new SqlCommand("SELECT SessionCart.Row_ID, SessionCart.orderNum, SessionCart.custCode, SessionCart.qtySold, SessionCart.prodCode," +
                                             "SessionCart.itemComment, SessionCart.Unit_ID, Products.Description, Products.Pk_Wt_Sz, Products.Pack, Products.Weight," +
                                             " Products.Case_ID, Products.Each_ID, Products.Pound_ID, Products.Default_ID, " +
                                             "Prices.Sell_Price, Prices.SellID, Products.Product_Categ FROM SessionCart INNER JOIN Products ON SessionCart.ProdCode = " +
                                             "Products.Product_Code INNER JOIN Prices ON SessionCart.ProdCode = Prices.Product_Code " +
                                             "AND sessionCart.Unit_ID = Prices.SellID WHERE (SessionCart.orderNum = @orderNum" +
                                             ") AND (Prices.Price_Level = @priceLevel AND Prices.Sell_Price > 0) ORDER BY SessionCart.Row_ID;", connect);
                        cmd.Parameters.AddWithValue("@orderNum", orderNumber);
                        cmd.Parameters.AddWithValue("@priceLevel", priceLevel);
                    }

                    else
                    {
                        cmd = new SqlCommand("SELECT SessionCart.Row_ID, SessionCart.orderNum, SessionCart.custCode, SessionCart.qtySold, SessionCart.prodCode," +
                                             "SessionCart.itemComment, SessionCart.Unit_ID, Products.Description, Products.Pk_Wt_Sz, Products.Pack, Products.Weight ," +
                                             " Products.Case_ID, Products.Each_ID, Products.Pound_ID, Products.Product_Categ, Products.Default_ID, Prices.SellID " +
                                             " FROM SessionCart INNER JOIN Products ON SessionCart.ProdCode = Products.Product_Code INNER JOIN Prices ON SessionCart.ProdCode = Prices.Product_Code" +
                                             " AND sessionCart.Unit_ID = Prices.SellID WHERE (SessionCart.orderNum = @orderNum) AND (Prices.Price_Level = @priceLevel AND Prices.Sell_Price > 0) ORDER BY SessionCart.Row_ID; ", connect);
                        cmd.Parameters.AddWithValue("@custCode", custCode);
                        cmd.Parameters.AddWithValue("@orderNum", orderNumber);
                        cmd.Parameters.AddWithValue("@priceLevel", priceLevel);
                    }

                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable      dt = new DataTable();
                    da.Fill(dt);

                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            OrderGuides.OrderGuide og = new OrderGuides.OrderGuide();

                            if (login.GetLoggedInUser.m_showPrices > 0)
                            {
                                og.showPrices = true;
                                og.sellPrice  = dr["Sell_Price"].ToString();
                            }
                            else
                            {
                                og.showPrices = false;
                            }

                            og.RowID = Convert.ToInt64(dr["Row_ID"].ToString());
                            og.Code  = dr["prodCode"].ToString().Trim();
                            if (dr["Product_Categ"].ToString().Contains("17-") || dr["Product_Categ"].ToString().Contains("19-"))
                            {
                                og.isManufactured = true;
                                og.Weight         = Convert.ToDouble(dr["Weight"]);
                            }
                            else
                            {
                                og.isManufactured = false;
                            }
                            og.Comment  = dr["itemComment"].ToString();
                            og.Qty      = Convert.ToDouble(dr["qtySold"].ToString());
                            og.SellID   = dr["SellID"].ToString();
                            og.Case_ID  = dr["Case_ID"].ToString();
                            og.Each_ID  = dr["Each_ID"].ToString();
                            og.Pound_ID = dr["Pound_ID"].ToString();

                            if (og.SellID == "C")
                            {
                                if (!string.IsNullOrEmpty(og.Case_ID))
                                {
                                    og.Unit = og.Case_ID;
                                }
                                else
                                {
                                    og.Unit = "Cs";
                                }
                            }

                            else if (og.SellID == "E")
                            {
                                if (!string.IsNullOrEmpty(og.Each_ID))
                                {
                                    og.Unit = og.Each_ID;
                                }
                                else
                                {
                                    og.Unit = "Ea";
                                }
                            }

                            else
                            {
                                if (!string.IsNullOrEmpty(og.Pound_ID))
                                {
                                    og.Unit = og.Pound_ID;
                                }
                                else
                                {
                                    og.Unit = "Lb";
                                }
                            }


                            og.Description = dr["Description"].ToString();
                            og.PackWeight  = dr["Pk_Wt_Sz"].ToString();
                            if (og.PackWeight == "" || og.PackWeight == string.Empty)
                            {
                                og.PackWeight = dr["Pack"].ToString() + "/" + dr["Weight"].ToString();
                            }
                            OrderGuides.Add(og);
                        }
                    }

                    else
                    {
                        Request.CreateResponse(HttpStatusCode.OK, "Current Order is Empty.");
                    }
                }
            }

            catch (Exception ex)
            {
                Logger.WriteLine("Exception @ GetSessionCart() : " + ex.Message);
                return(Request.CreateResponse(HttpStatusCode.NotFound, ex));
            }

            var message = Request.CreateResponse(HttpStatusCode.OK, OrderGuides);

            message.Headers.Location = new Uri(Request.RequestUri.ToString());
            Logger.WriteLine("Fetching SessionCart successful.");
            return(message);
        }
        public HttpResponseMessage ShowMasterOrderGuide(int groupID)
        {
            Logger.WriteLine("Fetching master order guide content....");
            SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConnection"].ConnectionString);

            string userName = login.GetLoggedInUser.custCode;

            try
            {
                List <OrderGuides.OrderGuide> orderguide = new List <OrderGuides.OrderGuide>();
                using (connect)
                {
                    SqlCommand cmd = new SqlCommand("MOG_showGuide", connect);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@groupID", groupID);
                    cmd.Parameters.AddWithValue("@custCode", userName);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    DataTable      dt      = new DataTable();
                    adapter.Fill(dt);

                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            OrderGuides.OrderGuide od = new OrderGuides.OrderGuide();
                            od.groupID   = groupID;
                            od.delColumn = "<a data-toggle='tooltip' data-placement='right' title='Delete Item From Guide' class='DelFrmGuide' href='#Delete' id ='deleteGuideBtn'><span class='glyphicon glyphicon-minus-sign'></a>";
                            od.Code      = row["prodCode"].ToString().Trim();
                            if (od.Code == string.Empty || od.Code == null)
                            {
                                var msg = Request.CreateResponse(HttpStatusCode.OK, "no content");
                                msg.Headers.Location = new Uri(Request.RequestUri.ToString());
                                return(msg);
                            }
                            od.Description = row["Description"].ToString();
                            od.PackWeight  = row["Pk_Wt_Sz"].ToString();
                            if (od.PackWeight == "" || od.PackWeight == string.Empty)
                            {
                                od.PackWeight = row["Pack"].ToString() + "/" + row["Weight"].ToString();
                            }
                            od.Qty       = Convert.ToInt16(row["qty"].ToString());
                            od.Unit      = row["unit_id"].ToString();
                            od.Comment   = row["itemComment"].ToString();
                            od.sortOrder = Convert.ToInt32(row["sortOrder"]);
                            orderguide.Add(od);
                        }
                    }
                }

                var message = Request.CreateResponse(HttpStatusCode.OK, orderguide);
                message.Headers.Location = new Uri(Request.RequestUri.ToString());
                Logger.WriteLine("Fetching master order guide content successful. Group ID: " + groupID.ToString());
                return(message);
            }

            catch (Exception ex)
            {
                Logger.WriteLine("Exception @ ShowMasterOrderGuide() : " + ex.Message);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }