예제 #1
0
        public static void JSONRetailerDebug(Retailer ret)
        {
            string serializedRet = SerializeRetailer(ret);

            Console.WriteLine(serializedRet);
            Retailer jsonRetailer = DeSerializeRetailer(serializedRet);

            Console.WriteLine(jsonRetailer.ToString());
        }
예제 #2
0
        public void AddRetailer(Retailer ret)
        {
            DBController dbc = new DBController();

            try {
                dbc.AddRetailer(ret);
            } catch (NpgsqlException e) {
                Console.WriteLine((Program.sqlDebugMessages) ? "AddRetailer: " + e.BaseMessage.ToString() : "");
                WebOperationContext ctx = WebOperationContext.Current;
                ctx.OutgoingResponse.StatusCode        = System.Net.HttpStatusCode.Conflict;
                ctx.OutgoingResponse.StatusDescription = e.BaseMessage;
            } finally {
                dbc.Close();
            }
        }
예제 #3
0
        public int AddRetailer(Retailer retailerToInsert)
        {
            string sql = "INSERT INTO retailers(latitude, longitude, companyname, description, openinghours) VALUES (@latitude, @longitude, @companyname, @description, @openinghours) RETURNING retailerid";

            NpgsqlCommand command = new NpgsqlCommand(sql, conn);

            command.Parameters.AddWithValue("@latitude", retailerToInsert.GetOrSetLatitude);
            command.Parameters.AddWithValue("@longitude", retailerToInsert.GetOrSetLongitude);
            command.Parameters.AddWithValue("@companyname", retailerToInsert.GetOrSetCompanyName);
            command.Parameters.AddWithValue("@description", retailerToInsert.GetOrSetDescription);
            command.Parameters.AddWithValue("@openinghours", retailerToInsert.GetOrSetOpeningHours);

            return(Int32.Parse(command.ExecuteScalar().ToString()));
            //return NonQuery(command, "retailers");
        }
예제 #4
0
        public void save(List <Dealer> dealers, List <Store> stores, List <Offer> offers)
        {
            //Go through all eTilbudsAvisen stores and create equivalent Retailers from the data, recognized by the Database
            foreach (Store store in stores)
            {
                Retailer retailer = new Retailer();
                retailer.GetOrSetLatitude  = store.latitude.ToString();
                retailer.GetOrSetLongitude = store.longitude.ToString();

                //Fetch relevant data from the eTilbudsAvisen dealer, to fill in more blanks of Retailer
                foreach (Dealer dealer in dealers)
                {
                    //Match the dealer id of store with the actual dealer
                    if (store.dealer_id == dealer.Id)
                    {
                        retailer.GetOrSetCompanyName = dealer.Name;
                    }
                }

                // Got no proper data for opening hours or description yet.
                retailer.GetOrSetOpeningHours = null;

                String categories;
                if (store.category_ids.Count != 0)
                {
                    categories = store.category_ids[0];
                    for (int i = 1; i < store.category_ids.Count - 1; i++)
                    {
                        categories += ',' + store.category_ids[i];
                    }
                }
                else
                {
                    categories = "No Categories";
                }

                retailer.GetOrSetDescription = categories;

                //Put the retailer into the Database
                DBController dbc        = new DBController();
                int          databaseId = dbc.AddRetailer(retailer);
                RetailerIdMap.Add(store.id, databaseId);
                dbc.Close();
            }
            // Move on to convert and save all offers
            //saveOffers(offers);
        }
예제 #5
0
        public List <Retailer> GetAllRetailers()
        {
            string            sql          = String.Format("SELECT * FROM retailers");
            DataRowCollection res          = Query(sql);
            List <Retailer>   allRetailers = new List <Retailer>();

            if (res.Count >= 1)
            {
                foreach (DataRow datarow in res)
                {
                    Retailer retailer = new Retailer(datarow);
                    allRetailers.Add(retailer);
                }
                return(allRetailers);
            }
            else
            {
                return(allRetailers);
            }
        }
예제 #6
0
        public Retailer GetRetailerById(int retailerId)
        {
            DBController        dbc = new DBController();
            WebOperationContext ctx = WebOperationContext.Current;

            try {
                Retailer tempRet = dbc.GetRetailerById(retailerId);
                if (tempRet != null)
                {
                    return(tempRet);
                }
            } catch (NpgsqlException e) {
                Console.WriteLine((Program.sqlDebugMessages) ? "GetRetailerById: " + e.BaseMessage.ToString() : "");
                ctx.OutgoingResponse.StatusCode        = System.Net.HttpStatusCode.Conflict;
                ctx.OutgoingResponse.StatusDescription = e.BaseMessage;
                return(null);
            } finally {
                dbc.Close();
            }
            ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NoContent;
            return(null);
        }
예제 #7
0
        public static Retailer GetTestRetailer()
        {
            Retailer ret = new Retailer("57.052648", "9.917516", "SuperBrugsen", "Description af superbrugsen", "noget med openinghours");

            return(ret);
        }
예제 #8
0
        public static Retailer DeSerializeRetailer(string ret)
        {
            Retailer deserializedRet = JSONHelper.Deserialize <Retailer>(ret);

            return(deserializedRet);
        }
예제 #9
0
        //Retailer
        public static string SerializeRetailer(Retailer ret)
        {
            string serializedRet = JSONHelper.Serialize <Retailer>(ret);

            return(serializedRet);
        }