public IActionResult Delete(int id) { try { ShopLink db_shopLink = _shopLinkContext.GetWithId(id); if (db_shopLink == null) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Messages = new Message[] { new Message { Lang_id = 1, MessageLang = "Model state isn't valid!" }, new Message { Lang_id = 2, MessageLang = "Состояние модели недействительно!" }, new Message { Lang_id = 3, MessageLang = "Model vəziyyəti etibarsızdır!" } } })); } _shopLinkContext.Detele(id); return(Ok()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async System.Threading.Tasks.Task <ActionResult> Confirm(long charge_id) { string myShopifyUrl = db.ShopLinks.Where(w => w.PremiumID == charge_id).FirstOrDefault().Shop; string accessToken = db.ShopLinks.Where(w => w.PremiumID == charge_id).FirstOrDefault().Token; try { var service = new RecurringChargeService(myShopifyUrl, accessToken); var charge = await service.GetAsync(charge_id); if (charge.Status == "accepted") { await service.ActivateAsync(charge_id); ShopLink link = db.ShopLinks.Where(w => w.Shop == myShopifyUrl).FirstOrDefault(); link.IsPremium = true; db.Entry(link).Property(w => w.IsPremium).IsModified = true; db.SaveChanges(); } else if (charge.Status == "declined") { return(RedirectToAction("Failed", "Premium")); } return(RedirectToAction("Install", "Home", new { shop = myShopifyUrl })); } catch { return(RedirectToAction("UrlBreak", "Home")); } }
public async System.Threading.Tasks.Task <ActionResult> Buy() { string myShopifyUrl = Session["shop"].ToString(); string accessToken = db.ShopLinks.Where(w => w.Shop == myShopifyUrl).FirstOrDefault().Token; try { var service = new RecurringChargeService(myShopifyUrl, accessToken); var charge = new RecurringCharge() { Name = "Premium Account", Price = 7, /* Test= true,*/ //Test = true, //Marks this charge as a test, meaning it won't charge the shop owner. ReturnUrl = "https://www.leaderpush.com/Premium/Confirm" }; charge = await service.CreateAsync(charge); ShopLink link = db.ShopLinks.Where(w => w.Shop == myShopifyUrl).FirstOrDefault(); link.PremiumID = charge.Id; db.Entry(link).Property(w => w.PremiumID).IsModified = true; db.SaveChanges(); return(Redirect(charge.ConfirmationUrl)); } catch { return(RedirectToAction("UrlBreak", "Home")); } }
public void SetNormalHttpUrl() { string sign = "http:"; //对于不规范的http的URL增加http GoodHref = string.IsNullOrEmpty(GoodHref) ? GoodHref : (GoodHref.Contains(sign) ? GoodHref : sign + GoodHref); ShopLink = string.IsNullOrEmpty(ShopLink) ? ShopLink : (ShopLink.Contains(sign) ? ShopLink : sign + ShopLink); productImg = string.IsNullOrEmpty(productImg) ? productImg : (productImg.Contains(sign) ? productImg : sign + productImg); }
public IActionResult Post([FromForm] ShopLink shopLink) { try { if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Messages = new Message[] { new Message { Lang_id = 1, MessageLang = "Model state isn't valid!" }, new Message { Lang_id = 2, MessageLang = "Состояние модели недействительно!" }, new Message { Lang_id = 3, MessageLang = "Model vəziyyəti etibarsızdır!" } } })); } Shop db_shop = _shopContext.GetWithId(shopLink.ShopId); if (db_shop == null) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Messages = new Message[] { new Message { Lang_id = 1, MessageLang = "Model state isn't valid!" }, new Message { Lang_id = 2, MessageLang = "Состояние модели недействительно!" }, new Message { Lang_id = 3, MessageLang = "Model vəziyyəti etibarsızdır!" } } })); } _shopLinkContext.Add(shopLink); return(Ok()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public ActionResult Go(string Title, string Body, string Link, HttpPostedFileBase Upload) { string shop = Session["shop"].ToString(); if (db.ShopLinks.Where(w => w.Shop == shop).FirstOrDefault().SendLimit > 0) { if (Upload.ContentLength > 0) { string nameOfFile = DateTime.Now.ToString("yyyyMMddHHmmss") + Upload.FileName; var path = Server.MapPath("~/Public/images/" + Path.GetFileName(nameOfFile)); Upload.SaveAs(path); filename = nameOfFile; } List <LeaderPush.Models.User> users = db.Users.Where(w => w.Store == shop).ToList(); foreach (var item in users) { Json json = new Json(); json.title = Title; json.body = Body; json.image = "images/" + filename; json.link = "//" + Link; string output = JsonConvert.SerializeObject(json); var pushEndpoint = item.PushEndpoint; var p256dh = item.P256dh; var auth = item.Auth; var subject = @"mailto:[email protected]"; var publicKey = @"BAS21PmINNueC0awLLy-VE6FMManBBJMZT6NUAwb3Ou0gsAuuMrYwiJGnW4f__ew1yIh1VnXVwCNTpFDig6i7eA"; var privateKey = @"mXjwDyDRBb48nDdUyUtWFpLfenacZP7sHJJjNUsXM2Q"; var subscription = new PushSubscription(pushEndpoint, p256dh, auth); var vapidDetails = new VapidDetails(subject, publicKey, privateKey); var gcmAPIKey = @"AIzaSyBH2nwvAeBZ_lRPPmxNkS8YF6_noPzAUfM"; var webPushClient = new WebPushClient(); try { webPushClient.SendNotification(subscription, output, vapidDetails); webPushClient.SendNotification(subscription, output, gcmAPIKey); } catch (WebPushException exception) { Console.WriteLine("Http STATUS code" + exception.StatusCode); } } ShopLink link = db.ShopLinks.Where(w => w.Shop == shop).FirstOrDefault(); link.SendLimit -= 1; db.Entry(link).Property(w => w.SendLimit).IsModified = true; db.SaveChanges(); return(RedirectToAction("Done", "Send")); // return Content(filename); } return(RedirectToAction("Failed", "Send")); }
public async System.Threading.Tasks.Task <ActionResult> auth() { DB list = new DB(); string code = Request.QueryString["code"]; string myShopifyUrl = Request.QueryString["shop"]; /*TRY-Catch*/ try { string accessToken = await AuthorizationService.Authorize(code, myShopifyUrl, API, Secret); Session["token"] = accessToken; var qs = Request.QueryString.ToKvps(); if (AuthorizationService.IsAuthenticRequest(qs, Secret)) { Session["shop"] = myShopifyUrl; if (db.ShopLinks.Where(w => w.Shop == myShopifyUrl).Count() > 0) { list.shopLinks = db.ShopLinks.ToList(); if (db.ShopLinks.Where(w => w.Shop == myShopifyUrl).FirstOrDefault().IsPremium == true) { Session["premium"] = true; } list.users = db.Users.ToList(); } else { ShopLink NewShop = new ShopLink(); NewShop.Shop = myShopifyUrl; NewShop.Token = accessToken; NewShop.InstallDate = DateTime.Now; NewShop.IsPremium = false; NewShop.SendLimit = 500; db.ShopLinks.Add(NewShop); db.SaveChanges(); list.shopLinks = db.ShopLinks.ToList(); list.users = db.Users.ToList(); var service = new ScriptTagService(myShopifyUrl, accessToken); var tag = new ScriptTag() { Event = "onload", Src = "https://www.leaderpush.com/public/scripts/main.js", }; tag = await service.CreateAsync(tag); } } else { //Request is not authentic and should not be acted on. return(Content("Error, Please Try Again...")); } return(View(list)); } catch { return(RedirectToAction("UrlBreak", "Home")); } }
public void Update(ShopLink data) { _context.Update(data); }
public void Add(ShopLink data) { _context.Add(data); }