예제 #1
0
        public static Offers GetTestOffers()
        {
            DateTime dt  = DateTime.Now;
            DateTime dt2 = dt.AddDays(3);
            Offers   off = new Offers(1, 1, dt, dt2, 20, 10, 10, 0.5m, 0.5m);

            return(off);
        }
예제 #2
0
        public static void JSONOffersDebug(Offers off)
        {
            string serializedOffers = SerializeOffers(off);

            Console.WriteLine(serializedOffers);
            Offers jsonOffers = DeSerializeOffers(serializedOffers);

            Console.WriteLine(jsonOffers.ToString());
        }
예제 #3
0
        private void saveOffers(List <Offer> offers)
        {
            // Variables that needs to be calculated
            decimal?kroner_savings;
            decimal?percent_saving_retailer;

            // Go through all eTilbudsAvisen offers and create equivalent dbOffers from the data, recognized by the Database
            for (int i = 0; i < offers.Count - 1; i++)
            {
                Offers dbOffers = new Offers();

                // If an offer can not be mapped to a retailer, skip the offer
                if (RetailerIdMap.ContainsKey(offers[i].store_id))
                {
                    //Convert values of offers to dbOffers
                    dbOffers.GetOrSetRetailerId  = RetailerIdMap[offers[i].store_id];
                    dbOffers.GetOrSetOfferFrom   = XmlConvert.ToDateTime(offers[i].run_from, XmlDateTimeSerializationMode.Utc);
                    dbOffers.GetOrSetOfferTo     = XmlConvert.ToDateTime(offers[i].run_till, XmlDateTimeSerializationMode.Utc);
                    dbOffers.GetOrSetOnSalePrice = (decimal)offers[i].pricing.price;

                    //Some items does not have values; directly, or because they can't be calculated: give default value of -1.0
                    if (String.IsNullOrEmpty(offers[i].pricing.pre_price.ToString()))
                    {
                        dbOffers.GetOrSetNormalPrice              = defaultValue;
                        dbOffers.GetOrSetKrSaving                 = defaultValue;
                        dbOffers.GetOrSetPercentageSavingGeneral  = defaultValue;
                        dbOffers.GetOrSetPercentageSavingRetailer = defaultValue;

                        //If variables have values, calculate and/or convert them to an appropriate format.
                    }
                    else
                    {
                        dbOffers.GetOrSetNormalPrice = (decimal)offers[i].pricing.pre_price;
                        kroner_savings            = dbOffers.GetOrSetNormalPrice - dbOffers.GetOrSetOnSalePrice;
                        dbOffers.GetOrSetKrSaving = kroner_savings;
                        percent_saving_retailer   = (dbOffers.GetOrSetOnSalePrice / dbOffers.GetOrSetNormalPrice) * 100;
                        dbOffers.GetOrSetPercentageSavingRetailer = percent_saving_retailer;

                        //TODO: once the database has been set up and each offer has been matched with ingredient, do this.
                        dbOffers.GetOrSetPercentageSavingGeneral = (decimal) - 1.0;
                    }

                    //TODO: ingredientId?? - See TODO above
                    dbOffers.GetOrSetIngredientId = 1;

                    //Save to Database
                    DBController dbc = new DBController();
                    dbc.AddOffers(dbOffers);
                    dbc.Close();
                }
            }
        }
예제 #4
0
        public void AddOffers(Offers off)
        {
            DBController dbc = new DBController();

            try {
                dbc.AddOffers(off);
            } catch (NpgsqlException e) {
                Console.WriteLine((Program.sqlDebugMessages) ? "AddOffers: " + e.BaseMessage.ToString() : "");
                WebOperationContext ctx = WebOperationContext.Current;
                ctx.OutgoingResponse.StatusCode        = System.Net.HttpStatusCode.Conflict;
                ctx.OutgoingResponse.StatusDescription = e.BaseMessage;
            } finally {
                dbc.Close();
            }
        }
예제 #5
0
        public int AddOffers(Offers offersToInsert)
        {
            string sql = "INSERT INTO offers(retailerid, ingredientid, offerfrom, offerto, normalprice, onsaleprice, krsaving, percentagesavingretailer, percentagesavinggeneral) "
                         + "VALUES (@retailerid, @ingredientid, @offerfrom, @offerto, @normalprice, @onsaleprice, @krsaving, @percentagesavingretailer, @percentagesavinggeneral)";

            NpgsqlCommand command = new NpgsqlCommand(sql, conn);

            command.Parameters.AddWithValue("@retailerid", offersToInsert.GetOrSetRetailerId);
            command.Parameters.AddWithValue("@ingredientid", offersToInsert.GetOrSetIngredientId);
            command.Parameters.AddWithValue("@offerfrom", offersToInsert.GetOrSetOfferFrom);
            command.Parameters.AddWithValue("@offerto", offersToInsert.GetOrSetOfferTo);
            command.Parameters.AddWithValue("@normalprice", offersToInsert.GetOrSetNormalPrice);
            command.Parameters.AddWithValue("@onsaleprice", offersToInsert.GetOrSetOnSalePrice);
            command.Parameters.AddWithValue("@krsaving", offersToInsert.GetOrSetKrSaving);
            command.Parameters.AddWithValue("@percentagesavingretailer", offersToInsert.GetOrSetPercentageSavingRetailer);
            command.Parameters.AddWithValue("@percentagesavinggeneral", offersToInsert.GetOrSetPercentageSavingGeneral);

            return(NonQuery(command, "offers"));
        }
예제 #6
0
        public List <Offers> GetAllOffers()
        {
            string            sql       = String.Format("SELECT * FROM offers");
            DataRowCollection res       = Query(sql);
            List <Offers>     allOffers = new List <Offers>();

            if (res.Count >= 1)
            {
                foreach (DataRow datarow in res)
                {
                    Offers offers = new Offers(datarow);
                    allOffers.Add(offers);
                }
                return(allOffers);
            }
            else
            {
                return(allOffers);
            }
        }
예제 #7
0
        public static Offers DeSerializeOffers(string off)
        {
            Offers deserializedOffers = JSONHelper.Deserialize <Offers>(off);

            return(deserializedOffers);
        }
예제 #8
0
        //Offers
        public static string SerializeOffers(Offers off)
        {
            string serializedOffers = JSONHelper.Serialize <Offers>(off);

            return(serializedOffers);
        }