Beispiel #1
0
 public static void StoreWatche(CasioWatch watch)
 {
     using (var db = new WebScrappingContext())
     {
         if (watch != null)
         {
             db.CasioWatch.Add(watch);
             db.SaveChanges();
         }
     }
 }
Beispiel #2
0
        public static CasioWatch GetSingleWatchFromDB(string watchName)
        {
            using (var db = new WebScrappingContext())
            {
                var query = from watchdb in db.CasioWatch
                            where watchdb.Name == watchName
                            select watchdb;

                CasioWatch watch = query.SingleOrDefault <CasioWatch>();
                return(watch);
            }
        }
        public static CasioWatch ConvertToDBModelInitial(WatchCasioBgScrappeDTO scrapedWatchModel)
        {
            CasioWatch watch = new CasioWatch();
            decimal    scrapedWatchModelPrice = 0;

            try
            {
                scrapedWatchModelPrice = Convert.ToDecimal(scrapedWatchModel.Price.Trim());
            }
            catch (Exception e)
            {
                string removeCharacters = Regex.Replace(scrapedWatchModel.Price.Trim(), "[^.0-9]", "");
                scrapedWatchModelPrice = Convert.ToDecimal(removeCharacters);
            }

            watch.Price = scrapedWatchModelPrice;

            watch.Name = scrapedWatchModel.Name.Trim();

            watch.ImageUrl = scrapedWatchModel.ImageLink.Trim();

            watch.Description = scrapedWatchModel.WatchDescription;

            watch.WatchUrl = scrapedWatchModel.WatchUrl.Trim();

            watch.AmazonPosted = false;

            watch.AmazonPricePost = 0;

            watch.AmazonPriceSearchLowest = 0;

            watch.BetterPriceThanAmazon = false;

            WebClient client = null;

            try
            {
                client      = new WebClient();
                watch.Image = client.DownloadData(watch.WatchUrl);
            }
            catch (Exception e)
            {
                watch.Image = null;
            }
            finally
            {
                client.Dispose();
            }

            return(watch);
        }
Beispiel #4
0
 public static void UpdateWatch(CasioWatch watch)
 {
     // add logic to update only properties that are not null
     using (var db = new WebScrappingContext())
     {
         if (watch != null)
         {
             var query = from watchdb in db.CasioWatch
                         where watchdb.Name == watch.Name
                         select watchdb;
             CasioWatch updateWatch = query.SingleOrDefault <CasioWatch>();
             updateWatch.AmazonPosted          = watch.AmazonPosted;
             updateWatch.AmazonPricePost       = watch.AmazonPricePost;
             updateWatch.BetterPriceThanAmazon = watch.BetterPriceThanAmazon;
             updateWatch.Description           = watch.Description;
             updateWatch.Image    = watch.Image;
             updateWatch.ImageUrl = watch.ImageUrl;
             updateWatch.Name     = watch.Name;
             updateWatch.Price    = watch.Price;
             updateWatch.WatchUrl = watch.WatchUrl;
             db.SaveChanges();
         }
     }
 }