コード例 #1
0
        public ActionResult Index()
        {
            OrderRepository orderRepo = new OrderRepository();
            OrderDetailRepository orderDetailRepo = new OrderDetailRepository();

            string userEmail = User.Identity.Name;
            int userId = repository.GetByEmail(userEmail).PKUserId;
            List<Order> orders = new List<Order>();
            List<OrderDetail> orderDetails = new List<OrderDetail>();

            foreach (Order item in orderRepo.GetOrdersByFKUserId(userId))
            {

                foreach (OrderDetail odItem in orderDetailRepo.GetOrderDetailByFKOrderId(item.PKOrderId))
                {
                    orderDetails.Add(odItem);
                }
            }

              return  View(orderDetails);
        }
コード例 #2
0
        public ActionResult OrderDetail(OrderViewModel model)
        {
            OrderRepository orderRepo = new OrderRepository();
            OrderDetailRepository orderDetailRepo = new OrderDetailRepository();
            ProductRepository prodReop = new ProductRepository();

            Data.Order order = new Order();
            Data.OrderDetail orderDetail = new Data.OrderDetail();
            IEnumerable<Data.User> userList = userRepo.GetAllUsers();
            Data.User user = new Data.User();

            if (User.Identity.IsAuthenticated)
            {
                return PartialView("_OrderDetail", model);
            }
            else
            {

                foreach (Data.User u in userList)
                {
                    if (model.Email == u.EmailId)
                    {
                        //throw new ApplicationException("Email is already registered");
                        TempData["Msg"] = "Email is already registerd";
                        return RedirectToAction("CheckOut");
                    }
                }

                user.UserName = model.FirstName + " " + model.LastName;
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.EmailId = model.Email;
                user.Password = model.Password;
                user.Role = "U";
                int userId = userRepo.Create(user);
                order.FKUserId = userId;
                int orderId = orderRepo.Create(order);
                productId = (IList<string>)Session["ProId"];

                foreach (var item in productId)
                {
                    int id = Convert.ToInt32(item);
                    orderDetail.FKOrderId = orderId;
                    orderDetail.FKProductId = id;
                    orderDetail.Status = "In Store";
                    orderDetail.Quantity = (int)prodReop.GetById(id).Quantity;
                    orderDetail.Cost = (decimal)prodReop.GetById(id).Price;
                    orderDetailRepo.Create(orderDetail);
                    //products.Add(db.Products.Find(productId));
                }

            }

            return PartialView("_OrderDetail", model);
        }
コード例 #3
0
ファイル: OrderController.cs プロジェクト: mahmoodali31/shop
        public ActionResult OrderDetail(OrderViewModel model)
        {
            OrderRepository orderRepo = new OrderRepository();
            OrderDetailRepository orderDetailRepo = new OrderDetailRepository();

            ShippingAddressRepository shARepo = new ShippingAddressRepository();

            Data.Order order = new Order();

            Data.OrderDetail orderDetail = new Data.OrderDetail();

            UserAddress userAddress = new UserAddress();

            IEnumerable<Data.User> userList =userRepo.GetAllUsers();

            Data.User user = new Data.User();

            string body = null;

            using (StreamReader sr = new StreamReader(Server.MapPath("~/Template/EmailTemp.html")))
            {
                body = sr.ReadToEnd();

            }

            if (User.Identity.IsAuthenticated)
            {

                string userEmail = User.Identity.Name;
                currentUer = userRepo.GetByEmail(userEmail);

                order.FKUserId = currentUer.PKUserId;

                int orderId = orderRepo.Create(order);
                order.User = currentUer;

                productId = (IList<string>)Session["ProId"];

                foreach (var item in productId)
                {
                    int id = Convert.ToInt32(item);
                    orderDetail.FKOrderId = orderId;
                    orderDetail.FKProductId = id;
                    orderDetail.Status = "In Store";
                    orderDetail.Quantity = (int)prodReop.GetById(id).Quantity;
                    orderDetail.Cost = (decimal)prodReop.GetById(id).Price;

                    orderDetailRepo.Create(orderDetail);

                }
                model.UserName = currentUer.FirstName+" "+currentUer.LastName;
                userAddress = shARepo.GetAddressByUserId(currentUer.PKUserId);
                model.Address = userAddress.Address;
                model.Mobile = userAddress.Mobile;
                AddCart();
                model.Carts = cartReop.GetCartItems(currentUer.PKUserId);
                model.SubPrice = cart.Quantity * cart.Price;
                model.TotalPrice = Convert.ToDecimal(GetItemsPrice());
                TempData["Tax"] = .25;

               body = body.Replace("[UserName]", currentUer.FirstName + " " + currentUer.LastName);
                body = body.Replace("[Mobile]", userAddress.Mobile);
                body = body.Replace("[Adderss]", userAddress.Address);
                body = body.Replace("[Date]", DateTime.Now.ToString());
                body = RazorEngine.Razor.Parse(body, model);

                body = body.Replace("[SubPrice]", model.SubPrice.ToString());
                //body = body.Replace("[Tax]", tax.ToString());
                body = body.Replace("[TotalPrice]", model.TotalPrice.ToString());

                EmailUtility.SendEmail(userEmail, "E-Shop", body, null);
                cartReop.EmptyCart(currentUer.PKUserId);

                return View("OrderDetail", model);
            }

            else
            {
                user.UserName = model.FirstName + " " + model.LastName;
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.EmailId = model.Email;
                user.Password = model.Password;
                user.Role = "U";
                userId = userRepo.Create(user);
                order.FKUserId = userId;
                int orderId = orderRepo.Create(order);
                productId = (IList<string>)Session["ProId"];

                foreach (var item in productId)
                {
                    int id = Convert.ToInt32(item);
                    orderDetail.FKOrderId = orderId;
                    orderDetail.FKProductId = id;
                    orderDetail.Status = "In Store";
                    orderDetail.Quantity = (int)prodReop.GetById(id).Quantity;
                    orderDetail.Cost = (decimal)prodReop.GetById(id).Price;
                    orderDetailRepo.Create(orderDetail);

                }
                userAddress.FKUserId = userId;
                userAddress.Address = model.Address;
                userAddress.City = model.City;
                userAddress.State = model.State;
                userAddress.Mobile = model.Mobile;
                userAddress.Country = model.Country;

                userAddress.ZipCode = Convert.ToInt32(model.Zipcode);
                shARepo.Create(userAddress);

                TempData["UserName"] = model.FirstName + " " + model.LastName;
                TempData["Adderss"] = model.Address;
                TempData["Mobile"] = model.Mobile;
                TempData["Tax"] = .25;
                AddCart();
                model.Carts = cartReop.GetCartItems(userId);
                model.SubPrice = cart.Quantity * cart.Price;
                model.TotalPrice = Convert.ToDecimal(GetItemsPrice());

                decimal tax = Convert.ToDecimal(model.TotalPrice) * Convert.ToDecimal(.25f);

                body = body.Replace("[UserName]", model.FirstName + " " + model.LastName);
                body = body.Replace("[Mobile]", model.Mobile);
                body = body.Replace("[Adderss]", model.Address);
                body = body.Replace("[Date]", DateTime.Now.ToString());
                body = RazorEngine.Razor.Parse(body, model);

                body = body.Replace("[SubPrice]", model.SubPrice.ToString());
                body = body.Replace("[Tax]", tax.ToString());
                body = body.Replace("[TotalPrice]", model.TotalPrice.ToString());

               EmailUtility.SendEmail(model.Email, "E-Shop", body, null);
               cartReop.EmptyCart(userId);

                return PartialView("_OrderDetail", model);
            }
        }