示例#1
0
        public IActionResult Change(int id, int pid)
        {
            var userID    = Task.Run(async() => await userManager.FindByNameAsync(User.Identity.Name)).Result.Id;
            var rolecheck = (from role in context.UserRoles.ToList()
                             where role.UserId == userID
                             select role).FirstOrDefault();

            if (rolecheck != null)
            {
                var orderDetails = (from od in orderDetailRepository.Gets().ToList()
                                    where od.OrderId == id
                                    select od).ToList();
                foreach (var od in orderDetails)
                {
                    if (od.OrderId == id && od.Paid == false)
                    {
                        od.OrderId = pid;
                    }
                }
                var result = orderDetailRepository.Edits(orderDetails);
                if (result != null)
                {
                    var orderFrom = (from o in orderRepository.Gets()
                                     where o.OrderId == id
                                     select o).FirstOrDefault();
                    orderFrom.Using = false;
                    var orderTo = (from o in orderRepository.Gets()
                                   where o.OrderId == pid
                                   select o).FirstOrDefault();
                    orderTo.Using = true;
                    var resultFrom = orderRepository.Edit(orderFrom);
                    var resultTo   = orderRepository.Edit(orderTo);
                    if (resultTo != null && resultFrom != null)
                    {
                        var url = "https://localhost:44366/Home/Index/" + pid;
                        return(Redirect(url));
                    }
                }
                return(View());
            }
            return(RedirectToAction("AccessDenied", "Account"));
        }