Ejemplo n.º 1
0
        public async Task <IActionResult> Summarypost()
        {
            var clamidentity = (ClaimsIdentity)User.Identity;
            var claim        = clamidentity.FindFirst(ClaimTypes.NameIdentifier);

            detailcard.Listcart = await db.shopingCarts.Where(c => c.applicationuserid == claim.Value).ToListAsync();

            detailcard.OrderHeaders.orderdate = DateTime.Now;
            detailcard.OrderHeaders.userid    = claim.Value;
            detailcard.OrderHeaders.Status    = SD.StatusSubmitted;
            detailcard.OrderHeaders.Picktime  = Convert.ToDateTime(detailcard.OrderHeaders.PickDate.ToShortDateString()
                                                                   + " " + detailcard.OrderHeaders.Picktime.ToShortTimeString());
            List <OrderDatails> orderdetailslist = new List <OrderDatails>();

            db.OrderHeaders.Add(detailcard.OrderHeaders);
            await db.SaveChangesAsync();

            detailcard.OrderHeaders.OrdartotalOriginal = 0;

            foreach (var item in detailcard.Listcart)
            {
                item.Menuitem = await db.Menuitem.FirstOrDefaultAsync(m => m.id == item.menuitemid);

                OrderDatails orderDatails = new OrderDatails()
                {
                    Menuitemid  = item.menuitemid,
                    orderid     = detailcard.OrderHeaders.id,
                    Description = item.Menuitem.description,
                    name        = item.Menuitem.name,
                    price       = item.Menuitem.Price,
                    count       = item.count
                };
                detailcard.OrderHeaders.OrdartotalOriginal += orderDatails.count * orderDatails.price;
                db.OrderDatails.Add(orderDatails);
            }
            detailcard.OrderHeaders.copunslist = await db.Copuns.ToListAsync();

            if (HttpContext.Session.GetInt32(SD.sscouponcode) != null && HttpContext.Session.GetInt32(SD.sscouponcode) != 0)
            {
                Copuns cop = await db.Copuns.FirstOrDefaultAsync(x => x.id == HttpContext.Session.GetInt32(SD.sscouponcode));

                detailcard.OrderHeaders.ordertotal = SD.discount(cop, detailcard.OrderHeaders.OrdartotalOriginal);
                detailcard.OrderHeaders.CouponCode = cop.Name;
            }
            else
            {
                detailcard.OrderHeaders.ordertotal = detailcard.OrderHeaders.OrdartotalOriginal;
            }
            detailcard.OrderHeaders.CouponCodeDiscount = detailcard.OrderHeaders.OrdartotalOriginal - detailcard.OrderHeaders.ordertotal;
            db.RemoveRange(detailcard.Listcart);

            HttpContext.Session.SetInt32("sscartcount", 0);
            await db.SaveChangesAsync();

            return(RedirectToAction("confirm", "Order", new { id = detailcard.OrderHeaders.id }));
            //return RedirectToAction("index", "Home");
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Summary()
        {
            detailcard = new OrderDetails_ViewModel()
            {
                OrderHeaders = new OrderHeaders(),
            };
            detailcard.OrderHeaders.ordertotal = 0;
            var             clamidentity    = (ClaimsIdentity)User.Identity;
            var             claim           = clamidentity.FindFirst(ClaimTypes.NameIdentifier);
            ApplicationUser applicationuser = await db.ApplicationUser.FirstOrDefaultAsync(x => x.Id == claim.Value);

            var cart = db.shopingCarts.Where(x => x.applicationuserid == claim.Value);

            if (cart != null)
            {
                detailcard.Listcart = await cart.ToListAsync();
            }
            foreach (var list in detailcard.Listcart)
            {
                list.Menuitem = await db.Menuitem.FirstOrDefaultAsync(m => m.id == list.menuitemid);

                detailcard.OrderHeaders.ordertotal = detailcard.OrderHeaders.ordertotal + (list.Menuitem.Price * list.count);
            }
            detailcard.OrderHeaders.OrdartotalOriginal = detailcard.OrderHeaders.ordertotal;
            detailcard.OrderHeaders.Picupname          = applicationuser.Name;
            detailcard.OrderHeaders.Picktime           = DateTime.Now;
            detailcard.OrderHeaders.Phonenumber        = applicationuser.PhoneNumber;
            detailcard.OrderHeaders.copunslist         = await db.Copuns.ToListAsync();

            if (HttpContext.Session.GetInt32(SD.sscouponcode) != null && HttpContext.Session.GetInt32(SD.sscouponcode) != 0)
            {
                Copuns cop = await db.Copuns.FirstOrDefaultAsync(x => x.id == HttpContext.Session.GetInt32(SD.sscouponcode));

                detailcard.OrderHeaders.ordertotal = SD.discount(cop, detailcard.OrderHeaders.OrdartotalOriginal);
                detailcard.OrderHeaders.CouponCode = cop.Name;
            }
            if (HttpContext.Session.GetInt32(SD.sscouponcode) == 0)
            {
                detailcard.OrderHeaders.ordertotal = detailcard.OrderHeaders.OrdartotalOriginal;
            }
            return(View(detailcard));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Index()
        {
            detailcard = new OrderDetails_ViewModel()
            {
                OrderHeaders = new OrderHeaders(),
            };
            detailcard.OrderHeaders.ordertotal = 0;
            var clamidentity = (ClaimsIdentity)User.Identity;
            var claim        = clamidentity.FindFirst(ClaimTypes.NameIdentifier);
            var cart         = db.shopingCarts.Where(x => x.applicationuserid == claim.Value);

            if (cart != null)
            {
                detailcard.Listcart = await cart.ToListAsync();
            }
            foreach (var list in detailcard.Listcart)
            {
                list.Menuitem = await db.Menuitem.FirstOrDefaultAsync(m => m.id == list.menuitemid);

                detailcard.OrderHeaders.ordertotal = detailcard.OrderHeaders.ordertotal + (list.Menuitem.Price * list.count);
                if (list.Menuitem.description.Length > 100)
                {
                    list.Menuitem.description = list.Menuitem.description.Substring(0, 99) + "...";
                }
            }

            detailcard.OrderHeaders.OrdartotalOriginal = detailcard.OrderHeaders.ordertotal;
            detailcard.OrderHeaders.copunslist         = await db.Copuns.ToListAsync();

            if (HttpContext.Session.GetInt32(SD.sscouponcode) != null && HttpContext.Session.GetInt32(SD.sscouponcode) != 0)
            {
                Copuns cop = await db.Copuns.FirstOrDefaultAsync(x => x.id == HttpContext.Session.GetInt32(SD.sscouponcode));

                detailcard.OrderHeaders.ordertotal = SD.discount(cop, detailcard.OrderHeaders.OrdartotalOriginal);
            }
            if (HttpContext.Session.GetInt32(SD.sscouponcode) == 0)
            {
                detailcard.OrderHeaders.ordertotal = detailcard.OrderHeaders.OrdartotalOriginal;
            }
            return(View(detailcard));
        }