public IActionResult PaymentOption(PaymentFirstVM model)
        {
            if (HttpContext.GetLoggedUser() != null)
            {
                TempData["logged"] = "True";
            }

            var user = HttpContext.GetLoggedUser();

            var            details = con.BillingDetails.Where(x => x.UserId == user.Id).FirstOrDefault();
            BillingDetails billing = new BillingDetails();

            if (model.CustomerInfo != null && details != null)
            {
                details.Email         = model.CustomerInfo.Email;
                details.Fullname      = model.CustomerInfo.FullName;
                details.Zip           = model.CustomerInfo.Zip;
                details.Country       = model.CustomerInfo.Country;
                details.City          = model.CustomerInfo.City;
                details.StreetAddress = model.CustomerInfo.StreetAddress;
                details.UserId        = user.Id;
                details.PhoneNumber   = model.CustomerInfo.PhoneNumber;

                con.SaveChanges();
            }
            else
            {
                billing.Email         = model.CustomerInfo.Email;
                billing.Fullname      = model.CustomerInfo.FullName;
                billing.Zip           = model.CustomerInfo.Zip;
                billing.Country       = model.CustomerInfo.Country;
                billing.City          = model.CustomerInfo.City;
                billing.StreetAddress = model.CustomerInfo.StreetAddress;
                billing.UserId        = user.Id;
                billing.PhoneNumber   = model.CustomerInfo.PhoneNumber;

                con.Add(billing);
            }

            con.SaveChanges();
            int product = con.Products.Find(model.ProductId).Id;

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "HomePage"));
            }

            PaymentOptionVM pay = new PaymentOptionVM
            {
                Price       = model.Price,
                ProductName = model.ProductName,
                PaypalRoute = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&amount=" + model.Price.ToString() + "&[email protected]&item_name="
                              + model.ProductName + "&return=https://localhost:44342/Payment/PaymentSuccess?ProductId=" + product
            };

            return(View(pay));
        }
예제 #2
0
        public BlogPostCustom AddBlogPost(CreateBlogPostCustom addBlogPost)
        {
            if (addBlogPost != null)
            {
                string makeSlugFromTitle = null;
                makeSlugFromTitle = SlugRefactoring.Refactor(addBlogPost.blogPost.title);

                //if slug already exists in database return an empty object
                if (con.BlogPosts.Where(x => x.Slug == makeSlugFromTitle).Any())
                {
                    return(new BlogPostCustom("Object with this slug already exists"));
                }
                var model = new BlogPost()
                {
                    Slug        = makeSlugFromTitle,
                    Title       = addBlogPost.blogPost.title,
                    Description = addBlogPost.blogPost.description,
                    Body        = addBlogPost.blogPost.body,
                    CreatedAt   = DateTime.Now,
                    UpdatetAt   = DateTime.Now
                };
                con.Add(model);
                con.SaveChanges();

                //if new object has tags
                if (addBlogPost.blogPost.tagList != null)
                {
                    foreach (var tag in addBlogPost.blogPost.tagList)
                    {
                        var newTag = new Tag
                        {
                            TagName = tag
                        };
                        //if tag doesn't exist in database, add a new tag in a tag table
                        if (!con.Tags.Where(x => x.TagName == tag).Any())
                        {
                            con.Add(newTag);
                            con.SaveChanges();
                        }

                        // if exists, then find id and add in many-to-many table (BlogPostTag)
                        else
                        {
                            newTag.Id = con.Tags.Where(x => x.TagName == tag).FirstOrDefault().Id;
                        }
                        var blogtag = new BlogPostTag();
                        blogtag.BlogPostId = model.Id;
                        blogtag.TagId      = newTag.Id;
                        con.Add(blogtag);
                        con.SaveChanges();
                    }
                }

                //custom object for json return
                var bpc = new BlogPostCustom.BPCblog()
                {
                    title       = addBlogPost.blogPost.title,
                    description = addBlogPost.blogPost.description,
                    body        = addBlogPost.blogPost.body,
                    slug        = makeSlugFromTitle,
                    createdAt   = DateTime.Now,
                    updatedAt   = DateTime.Now,
                    tagList     = addBlogPost.blogPost.tagList
                };
                var bpcM = new BlogPostCustom()
                {
                    blogPost = bpc
                };
                return(bpcM);
            }

            return(new BlogPostCustom("Object provided as a parameter is null"));
        }