Example #1
0
        public async Task RunYoFreeSample(string connectionString)
        {
            YoFreeSample  yoFreeSample  = new YoFreeSample();
            List <string> udemyLinkList = yoFreeSample.CreateUdemyLinkList();

            Udemy         udemy      = new Udemy();
            List <Course> courseList = await udemy.CreateCourseList(udemyLinkList);

            Data data = new Data(connectionString);

            data.InsertCourse(courseList);
        }
Example #2
0
        public void Udemy()
        {
            customUrl           = "https://www.udemy.com/course/writing-with-flair-how-to-become-an-exceptional-writer/";
            customExpectedName  = "Writing With Flair: How To Become An Exceptional Writer"; //it's coming from <meta> og:title
            customExpectedPrice = 0;

            var udemy = new Udemy();

            udemy = udemy.Product(customUrl);

            Assert.Equal(customExpectedName, udemy.Name);
            Assert.Equal(customExpectedPrice, udemy.Price);
            Assert.Null(udemy.Error);
        }
Example #3
0
        public async Task RunCourseMania(string connectionString)
        {
            List <string> udemyLinkList = new List <string>();

            CourseMania courseMania = new CourseMania();

            udemyLinkList.AddRange(await courseMania.CreateUdemyLinkList());

            Udemy         udemy      = new Udemy();
            List <Course> courseList = await udemy.CreateCourseList(udemyLinkList);

            Data data = new Data(connectionString);

            data.InsertCourse(courseList);
        }
Example #4
0
        public async Task <IActionResult> AddItem(string itemLink, Guid needId)
        {
            var AuthenticatedUserId = Guid.Parse(User.Identity.GetUserId());

            var Need = await Context.Need.Where(x => x.Id == needId &&
                                                x.UserId == AuthenticatedUserId &&
                                                !x.IsRemoved &&
                                                x.NeedItem.Count() < maxItemCount).FirstOrDefaultAsync();

            if (Need != null)
            {
                if (Need.Stage == 1)
                {
                    if (itemLink.Contains("udemy.com"))
                    {
                        Udemy Udemy = new Udemy();
                        Udemy = Udemy.Product(itemLink);
                        if (Udemy.Error == null)
                        {
                            await AddNeedItem(Need.Id, Udemy.Link, Udemy.Name, Udemy.Price, "/image/udemy.png", "Udemy").ConfigureAwait(false);

                            return(Succes(null, Udemy, 201));
                        }
                        else
                        {
                            Logger.LogError("Udemy Error:{error}, Link:{link}", Udemy.Error, itemLink);
                            return(Error(Udemy.Error));
                        }
                    }
                    else if (itemLink.Contains("amazon.com.tr"))
                    {
                        Amazon Amazon = new Amazon();
                        Amazon = Amazon.Product(itemLink);
                        if (Amazon.Error == null)
                        {
                            await AddNeedItem(Need.Id, Amazon.Link, Amazon.Name, Amazon.Price, "/image/amazon.png", "Amazon").ConfigureAwait(false);

                            return(Succes(null, Amazon, 201));
                        }
                        else
                        {
                            Logger.LogError("Amazon Error:{error}, Link:{link}", Amazon.Error, itemLink);
                            return(Error(Amazon.Error));
                        }
                    }
                    else if (itemLink.Contains("pandora.com.tr"))
                    {
                        if (itemLink.ToLower().Contains("/kitap/"))
                        {
                            Pandora Pandora = new Pandora();
                            Pandora = Pandora.Product(itemLink);
                            if (Pandora.Error == null)
                            {
                                await AddNeedItem(Need.Id, Pandora.Link, Pandora.Name, Pandora.Price, Pandora.Picture, "Pandora").ConfigureAwait(false);

                                return(Succes(null, Pandora, 201));
                            }
                            else
                            {
                                Logger.LogError("Pandora Error:{error}, Link:{link}", Pandora.Error, itemLink);
                                return(Error(Pandora.Error));
                            }
                        }

                        return(Error("Pandora.com.tr'den sadece kitap seçebilirsiniz"));
                    }

                    return(Error("İhtiyaç duyduğunuz ürünü seçerken desteklenen platformları kullanın"));
                }

                return(Error("Bu kampanyada değişiklik yapamazsın", "Stage must be 1"));
            }

            return(Error("Kampanyanıza ulaşamadık, tekrar deneyin", "There is no campaign to add new item", null, 404));
        }
Example #5
0
        public async Task <JsonResult> NeedItemsPriceAndStatus(Guid needId) //checking and correcting needitem status, price.
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            var Need = await Context.Need.Include(need => need.NeedItem).FirstOrDefaultAsync(x => x.Id == needId && !x.IsRemoved);

            bool IsPageNeedRefresh = false;

            if (Need != null && Need.ShouldBeCheck)
            {
                Need.IsWrong = false; //need önceden hatalı olarak işaretlenmiş olabilir her ihtimale karşı hatasının gitmiş olabileceğini var sayarak,
                                      //false'lıyoruz eğer ki hala hatalıysa zaten tekrar hatalı olarak işaretlenecektir.
                var NeedItems = Need.NeedItem.Where(x => !x.IsRemoved).ToList();

                decimal TotalCharge = 0;
                foreach (var item in NeedItems)
                {
                    item.IsWrong = false;   //item önceden hatalı olarak işaretlenmiş olabilir her ihtimale karşı hatasının gitmiş olabileceğini var sayarak,
                                            //false'lıyoruz eğer ki hala hatalıysa zaten tekrar hatalı olarak işaretlenecektir.
                    if (item.PlatformName == "Amazon")
                    {
                        var Amazon = new Amazon();
                        Amazon = Amazon.Product(item.Link);

                        if (Amazon.Error == null)                    // herhangi bir hata yoksa
                        {
                            if (item.Price != (decimal)Amazon.Price) //ürünün amazon sisteminde ki fiyatı ile veritabanında ki fiyatı eşleşmiyorsa
                            {
                                IsPageNeedRefresh = true;
                                item.Price        = (decimal)Amazon.Price; //item'a yeni fiyatını al.
                            }
                        }
                        else // hatalı ise ürünü ve kampanyayı hatalı olarak işaretliyoruz, hatalı işaretlenen durumlar kontrol edilmesi için panelde görüntülenecek.
                        {
                            item.IsWrong = true;
                            Need.IsWrong = true;
                        }
                    }
                    else if (item.PlatformName == "Pandora")
                    {
                        var Pandora = new Pandora();
                        Pandora = Pandora.Product(item.Link);

                        if (Pandora.Error == null)
                        {
                            if (item.Price != (decimal)Pandora.Price)
                            {
                                IsPageNeedRefresh = true;
                                item.Price        = (decimal)Pandora.Price;
                            }
                        }
                        else
                        {
                            item.IsWrong = true;
                            Need.IsWrong = true;
                        }
                    }
                    else
                    {
                        var Udemy = new Udemy();
                        Udemy = Udemy.Product(item.Link);
                        //udemy fiyatı ile ilgili sorun var. sabit bir değer atılıyor, fiyat değişikliğini kontrol etmeye gerek yok.
                        if (Udemy.Error != null)
                        {
                            item.IsWrong = true;
                            Need.IsWrong = true;
                        }
                    }

                    TotalCharge += item.Price; //fiyat değişikliği kontrol edilip güncellenmesi gerekiyorsa güncellendikten sonra ki fiyatını almalıyız ki totalcharge'i da güncelleyebilelim.
                }

                if (!Need.IsWrong && Need.TotalCharge != TotalCharge) //kampanya hatalı olarak işaretlendiyse totalcharge güncellemesi yaptırmıyoruz.
                {
                    IsPageNeedRefresh = true;
                    Need.TotalCharge  = TotalCharge;
                }
                Need.LastCheckOn = DateTime.Now;

                await Context.SaveChangesAsync(); //değiştirilen bütün verileri sadece bir kere kaydediyoruz.
            }
            return(Json(new { IsPageNeedRefresh }));
        }
        public async Task AddItem(string ItemLink, long NeedId)
        {
            var Need = await Context.Need.Where(x => x.Id == NeedId &&
                                                !x.IsRemoved &&
                                                !x.IsSentForConfirmation &&
                                                x.NeedItem.Where(a => a.IsRemoved != true).Count() < 3) // en fazla 3 tane item(ihtiyaç) ekleyebilir.
                       .FirstOrDefaultAsync();

            // Kampanya(need) onaylanma için yollandıysa bir item ekleyemecek: onaylanma için gönderdiyse
            //(completed ve confirmed kontrol etmeye gerek yok çünkü onaylandıysa veya bittiyse de isSentForConfirmation hep true kalacak.)
            if (Need != null)
            {
                AuthUser = await GetAuthenticatedUserFromDatabaseAsync();

                if (Need.UserId == AuthUser.Id) //item(ihtiyaç) eklemeye çalıştığı kampanya Authenticated olmuş üzere aitse..
                {
                    if (ItemLink.ToLower().Contains("udemy.com"))
                    {
                        Udemy Udemy = new Udemy();
                        Udemy = Udemy.Product(ItemLink);
                        if (Udemy.Error == null)
                        {
                            await AddItemOnDBAndFixTotalCharge(Need.Id, Udemy.Link, Udemy.Name, (decimal)Udemy.Price, "/image/udemy.png", "Udemy");
                        }
                        else
                        {
                            Logger.LogError("Udemy Error:{error}, Link:{link}", Udemy.Error, ItemLink);
                            TempData["NeedMessage"] = Udemy.Error;
                        }
                    }
                    else if (ItemLink.ToLower().Contains("pandora.com.tr"))
                    {
                        if (ItemLink.ToLower().Contains("/kitap/"))
                        {
                            Pandora Pandora = new Pandora();
                            Pandora = Pandora.Product(ItemLink);
                            if (Pandora.Error == null)
                            {
                                await AddItemOnDBAndFixTotalCharge(Need.Id, Pandora.Link, Pandora.Name, (decimal)Pandora.Price, Pandora.Picture, "Pandora");
                            }
                            else
                            {
                                Logger.LogError("Pandora Error:{error}, Link:{link}", Pandora.Error, ItemLink);
                                TempData["NeedMessage"] = Pandora.Error;
                            }
                        }
                        else
                        {
                            TempData["MesajHata"] = "Pandora.com.tr'den sadece kitap seçebilirsiniz";
                        }
                    }
                    else if (ItemLink.ToLower().Contains("amazon.com.tr"))
                    {
                        Amazon Amazon = new Amazon();
                        Amazon = Amazon.Product(ItemLink);
                        if (Amazon.Error == null)
                        {
                            await AddItemOnDBAndFixTotalCharge(Need.Id, Amazon.Link, Amazon.Name, (decimal)Amazon.Price, "/image/amazon.png", "Amazon");
                        }
                        else
                        {
                            Logger.LogError("Amazon Error:{error}, Link:{link}", Amazon.Error, ItemLink);
                            TempData["NeedMessage"] = Amazon.Error;
                        }
                    }
                    else
                    {
                        TempData["MesajHata"] = "İhtiyacınızın linkini verirken desteklenen platformları kullanın";
                    }
                    Response.Redirect("/" + Need.User.Username.ToLower() + "/ihtiyac/" + Need.FriendlyTitle + "/" + Need.Id);
                }
            }
        }