public IActionResult Order(int status = 0, int page = 1)
        {
            var      json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp userTemp = null;

            if (json == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            userTemp = new UserTemp().Mapjson(json);

            string[] option = new String[] { "Ordering", "OrderSuccess", "All" };
            if (status <= 2)
            {
                ViewBag.option = option[status];
            }
            var             context = new istoreContext();
            List <Payorder> order   = null;

            if (status != 2)
            {
                order = context.Payorder.Where(P => P.Status == status).OrderByDescending(o => o.Date).ToList();
            }
            else
            {
                // ALL Order
                order = context.Payorder.OrderByDescending(o => o.Date).ToList();
            }


            return(View(order));
        }
        public IActionResult Index(Account account)
        {
            var      json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp userTemp = null;

            if (json == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            userTemp = new UserTemp().Mapjson(json);

            var context = new istoreContext();
            var ec      = new Encryption();

            var item = context.Account.Where(p => p.Email == userTemp.account.Email).FirstOrDefault();

            item.Password  = (account.Password == "" || account.Password == null) ? item.Password : ec.EncryptionText(account.Password);
            item.FirstName = account.FirstName;
            item.LastName  = account.LastName;
            item.Phone     = account.Phone;
            context.Update <Account>(item);
            context.SaveChanges();
            UpdateAppHttpContext(userTemp.account.Email);
            item.Password = "";
            return(View(item));
        }
示例#3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UserSwaggerConfig();

            AppHttpContext.Configure(app.ApplicationServices.
                                     GetRequiredService <Microsoft.AspNetCore.Http.IHttpContextAccessor>());

            app.UseHttpCacheHeaders();

            app.UseSession();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        public IActionResult Details(int Id)
        {
            var      json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp userTemp = null;

            if (json == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            userTemp = new UserTemp().Mapjson(json);

            List <Carts> CartsList = new List <Carts>();

            using (var context = new istoreContext())
            {
                var pay       = context.Payorder.Where(P => P.PayorderId == Id).ToList();
                var paydetail = context.Orderdetail.Join(pay, p => p.PayorderId, o => o.PayorderId, (o, p) => new
                {
                    orderId       = o.Id,
                    payorder_id   = p.PayorderId,
                    product_id    = o.ProductId,
                    product_price = o.ProductPrice,
                    quantity      = o.Quantity,
                    TotalPrice    = p.TotalPrice,
                    date          = p.Date
                });

                var pay_detail_product = context.Products.Join(paydetail, p => p.Id, pd => pd.product_id, (p, pd) => new
                {
                    pd.orderId,
                    pd.payorder_id,
                    pd.product_price,
                    pd.quantity,
                    pd.TotalPrice,
                    pd.date,
                    product = p
                });

                foreach (var i in pay_detail_product)
                {
                    i.product.Price = i.product_price;
                    CartsList.Add(
                        new Carts
                    {
                        Id                     = i.orderId,
                        AccountEmail           = userTemp.account.Email,
                        Product                = i.product,
                        Quantity               = i.quantity ?? 0,
                        AccountEmailNavigation = userTemp.account
                    });
                }
            }

            return(View(CartsList));
        }
 protected override void Execute(AppHttpContext context)
 {
     if (this._contentType == ContextType.JSON)
     {
         context.Context.Response.ContentType = "application/json";
     }
     else if (this._contentType == ContextType.HTML)
     {
         context.Context.Response.ContentType = "text/html";
     }
     else
     {
         context.Context.Response.ContentType = "text/text";
     }
     Next(context);
 }
示例#6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory, AmstramgramContext db)
        {
            var forwardedHeadersOptions = new ForwardedHeadersOptions
            {
                ForwardedHeaders      = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
                RequireHeaderSymmetry = false
            };

            forwardedHeadersOptions.KnownNetworks.Clear();
            forwardedHeadersOptions.KnownProxies.Clear();

            app.UseForwardedHeaders(forwardedHeadersOptions);

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            app.UseSession();

            app.Use((httpContext, nextMiddleware) =>
            {
                httpContext.Session.SetObject("_SessionKey", String.Empty);
                httpContext.Session.SetObject("_SessionDate", DateTime.Now);

                return(nextMiddleware());
            });

            app.UseStaticFiles();

            app.UseMvc();

            app.UseCookiePolicy();

            /*var optionsRewrite = new RewriteOptions()
             *                .AddRedirectToHttps(StatusCodes.Status301MovedPermanently, 63423);*/

            //app.UseRewriter(optionsRewrite);
            AppHttpContext.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>());
            // db.EnsureSeedData();
        }
        public IActionResult Index()
        {
            var      json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp userTemp = null;

            if (json == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            userTemp = new UserTemp().Mapjson(json);

            var context = new istoreContext();
            var item    = context.Account.Where(p => p.Email == userTemp.account.Email).FirstOrDefault();

            item.Password = "";

            return(View(item));
        }
        public IActionResult RemoveItem(int productid)
        {
            var      json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp userTemp = null;

            if (json == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            userTemp = new UserTemp().Mapjson(json);

            var   context = new istoreContext();
            Carts carts   = context
                            .Carts.Where(c => c.AccountEmail == userTemp.account.Email && c.ProductId == productid)
                            .FirstOrDefault();

            context.Remove <Carts>(carts);
            context.SaveChanges();
            UpdateAppHttpContext(userTemp.account.Email);
            return(RedirectToAction("Index"));
        }
        public IActionResult Checkout()
        {
            var      json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp userTemp = null;

            if (json == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            userTemp = new UserTemp().Mapjson(json);

            List <Carts> ItemCart = new List <Carts>();

            using (var context = new istoreContext())
            {
                IEnumerable <Carts> carts = context.Carts.Where(c => c.AccountEmail == userTemp.account.Email);
                var Datalist = carts.Join(context.Products, ca => ca.ProductId, pro => pro.Id,
                                          (ca, pro) => new
                {
                    Email    = ca.AccountEmail,
                    CartsID  = ca.Id,
                    Product  = pro,
                    Quantity = ca.Quantity
                });

                foreach (var i in Datalist)
                {
                    ItemCart.Add(new Carts
                    {
                        Id           = i.CartsID,
                        ProductId    = i.Product.Id,
                        Quantity     = i.Quantity,
                        AccountEmail = i.Email,
                        Product      = i.Product,
                    });
                }
            }

            return(View(ItemCart));
        }
示例#10
0
        public static void ProcessRequest()
        {
            AppHttpContext appContext = App.Instance.CreateContext(HttpContext.Current);
            var            midleware  = appContext.Next();

            if (null != midleware)
            {
                try
                {
                    midleware.Act(appContext);
                }
                catch (Exception ex)
                {
                    HttpContext.Current.Response.StatusCode = 500;
                }
            }
            else
            {
                HttpContext.Current.Response.StatusCode = 404;
            }
            HttpContext.Current.Response.End();
        }
示例#11
0
        public IActionResult AddItem(int productid, int quantity)
        {
            var      json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp userTemp = null;

            if (json == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            userTemp = new UserTemp().Mapjson(json);
            var   context = new istoreContext();
            Carts carts   = context
                            .Carts.Where(c => c.AccountEmail == userTemp.account.Email && c.ProductId == productid)
                            .FirstOrDefault();

            if (carts != null)
            {
                carts.Quantity += quantity;
                context.Update <Carts>(carts);
                context.SaveChanges();
            }
            else
            {
                Carts c = new Carts
                {
                    AccountEmail = userTemp.account.Email,
                    ProductId    = productid,
                    Quantity     = quantity
                };
                context.Carts.Add(c);
                context.SaveChanges();
            }

            UpdateAppHttpContext(userTemp.account.Email);

            return(RedirectToAction("Index"));
        }
 protected override void Execute(AppHttpContext context)
 {
     context.Context.Response.Write("[{\"id\": 1, \"nome\": \"Nome do cliente 01\"}, {\"id\": 2, \"nome\": \"Nome do cliente 02\"}]");
     Next(context);
 }
 public static IApplicationBuilder UseHttpContext(this IApplicationBuilder app)
 {
     AppHttpContext.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>());
     return(app);
 }
 protected override void Execute(AppHttpContext context)
 {
     context.Context.Response.Write("<h1>Hello World</h1>");
     Next(context);
 }
示例#15
0
 protected override void Execute(AppHttpContext context)
 {
     context.Context.Response.Write("{ \"message\": \"Hello World\", \"devcice\": \"" + context["Device"] + "\" }");
     Next(context);
 }
 protected override void Execute(AppHttpContext context)
 {
     context["Device"] = context.Context.Request.Headers["app-device"] ?? String.Empty;
     Next(context);
 }
示例#17
0
        public IActionResult Confirm(Payorder payorder)
        {
            var      json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp userTemp = null;

            if (json == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            userTemp = new UserTemp().Mapjson(json);
            if (userTemp.CartsCount == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }


            List <Orderdetail> order    = new List <Orderdetail>();
            List <Products>    products = new List <Products>();

            // getdata
            using (var context = new istoreContext())
            {
                IEnumerable <Carts> carts = context.Carts.Where(c => c.AccountEmail == userTemp.account.Email);
                var Datalist = carts.Join(context.Products, ca => ca.ProductId, pro => pro.Id,
                                          (ca, pro) => new
                {
                    Email    = ca.AccountEmail,
                    CartsID  = ca.Id,
                    Product  = pro,
                    Quantity = ca.Quantity
                });

                payorder.TotalPrice = 0;
                payorder.Email      = userTemp.account.Email;
                payorder.Date       = DateTime.Now;
                foreach (var i in Datalist)
                {
                    order.Add(new Orderdetail
                    {
                        Quantity     = i.Quantity,
                        ProductId    = i.Product.Id,
                        ProductPrice = i.Product.Price
                    });
                    payorder.TotalPrice += (i.Quantity * i.Product.Price);

                    if (i.Product.Amount - i.Quantity < 0)
                    {
                        RedirectToAction("Index", "Cart");
                    }
                    i.Product.Amount -= i.Quantity;
                    products.Add(i.Product);
                }
            }

            //save data
            using (var context = new istoreContext())
            {
                context.Payorder.Add(payorder);
                context.SaveChanges();
                foreach (var item in order)
                {
                    item.PayorderId = payorder.PayorderId;
                }
                context.AddRange(order);
                context.UpdateRange(products);
                var cartsList = context.Carts.Where(c => c.AccountEmail == "*****@*****.**").ToList();
                context.RemoveRange(cartsList);
                context.SaveChanges();
            }

            UpdateAppHttpContext(userTemp.account.Email);



            return(View());
        }
示例#18
0
        public string CheckProduct()
        {
            var             json     = AppHttpContext.Tempdate("Tempdata");
            UserTemp        userTemp = null;
            List <Products> product  = new List <Products>();

            if (json == null)
            {
                return(JsonConvert.SerializeObject(product, Formatting.Indented,
                                                   new JsonSerializerSettings
                {
                    PreserveReferencesHandling = PreserveReferencesHandling.Objects
                }));
            }

            userTemp = new UserTemp().Mapjson(json);
            List <Carts> ItemCart = new List <Carts>();

            using (var context = new istoreContext())
            {
                IEnumerable <Carts> carts = context.Carts.Where(c => c.AccountEmail == userTemp.account.Email);

                var Datalist = carts.Join(context.Products, ca => ca.ProductId, pro => pro.Id,
                                          (ca, pro) => new
                {
                    Email    = ca.AccountEmail,
                    CartsID  = ca.Id,
                    Product  = pro,
                    Quantity = ca.Quantity
                });


                foreach (var i in Datalist)
                {
                    ItemCart.Add(new Carts
                    {
                        Id           = i.CartsID,
                        ProductId    = i.Product.Id,
                        Quantity     = i.Quantity,
                        AccountEmail = i.Email,
                        Product      = i.Product,
                    });
                }
            }


            foreach (var item in ItemCart)
            {
                if (item.Quantity > item.Product.Amount)
                {
                    item.Product.Image = new byte[0];
                    product.Add(item.Product);
                }
            }


            string Productjson = JsonConvert.SerializeObject(product, Formatting.Indented,
                                                             new JsonSerializerSettings
            {
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            });


            return(Productjson);
        }