Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, ShippingDetailViewModel objAppointmentVM)
        {
            if (ModelState.IsValid)
            {
                objAppointmentVM.OrderCustomer.DateOrder = objAppointmentVM.OrderCustomer.DateOrder
                                                           .AddHours(objAppointmentVM.OrderCustomer.DateOrder.Hour)
                                                           .AddMinutes(objAppointmentVM.OrderCustomer.DateOrder.Minute);

                var appointmentFromDb = _db.OrderCustomers.Where(a => a.Id == objAppointmentVM.OrderCustomer.Id).FirstOrDefault();

                appointmentFromDb.CustomerName        = objAppointmentVM.OrderCustomer.CustomerName;
                appointmentFromDb.CustomerEmail       = objAppointmentVM.OrderCustomer.CustomerEmail;
                appointmentFromDb.CustomerPhoneNumber = objAppointmentVM.OrderCustomer.CustomerPhoneNumber;
                appointmentFromDb.DateOrder           = objAppointmentVM.OrderCustomer.DateOrder;
                appointmentFromDb.isConfirmed         = objAppointmentVM.OrderCustomer.isConfirmed;
                if (User.IsInRole(Sd.SuperAdminEndUser))
                {
                    appointmentFromDb.SalesPersonId = objAppointmentVM.OrderCustomer.SalesPersonId;
                }
                _db.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(objAppointmentVM));
        }
Ejemplo n.º 2
0
 public ActionResult Complete(ShippingDetailViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     TempData.Add("message", String.Format("Thank you {0}, you order is in process", model.ShippingDetails.FirstName));
     return(View());
 }
Ejemplo n.º 3
0
        public ActionResult Complete()
        {
            var model = new ShippingDetailViewModel
            {
                ShippingDetails = new ShippingDetails()
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public IActionResult Complete()
        {
            ShippingDetailViewModel shippingDetailViewModel = new ShippingDetailViewModel()
            {
                ShippingDetail = new ShippingDetail(),
            };

            return(View(shippingDetailViewModel));
        }
Ejemplo n.º 5
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var ShoesList = (IEnumerable <Shoes>)(from p in _db.Shoes
                                                  join a in _db.ProductSelectedForOrders
                                                  on p.Id equals a.ShoesId
                                                  where a.OrderCustomersID == id
                                                  select p).Include(p => p.ProductTypes).Include(p => p.Brands).Include(p => p.SpecialTags);
            ShippingDetailViewModel objVM = new ShippingDetailViewModel()
            {
                OrderCustomer = _db.OrderCustomers.Include(a => a.ApplicationUser).Where(a => a.Id == id).FirstOrDefault(),
                SalesPerson   = _db.ApplicationUsers.ToList(),
                Shoes         = ShoesList.ToList()
            };

            return(View(objVM));
        }
Ejemplo n.º 6
0
        //GET Delete
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var productList = (IEnumerable <Shoes>)(from p in _db.Shoes
                                                    join a in _db.ProductSelectedForOrders
                                                    on p.Id equals a.ShoesId
                                                    where a.OrderCustomersID == id
                                                    select p).Include("ProductTypes");

            ShippingDetailViewModel objAppointmentVM = new ShippingDetailViewModel()
            {
                OrderCustomer = _db.OrderCustomers.Include(a => a.ApplicationUser).Where(a => a.Id == id).FirstOrDefault(),
                SalesPerson   = _db.ApplicationUsers.ToList(),
                Shoes         = productList.ToList()
            };

            return(View(objAppointmentVM));
        }
        public IActionResult Complete(ShippingDetailViewModel shippingDetail)
        {
            if (!ModelState.IsValid)
            {
                return(View(shippingDetail));
            }
            else
            {
                ConfirmedOrderViewModel confirmedOrder = new ConfirmedOrderViewModel
                {
                    ShippingDetails = shippingDetail.ShippingDetails,
                    Cart            = _cartSessionService.GetCart()
                };

                string objectString = JsonConvert.SerializeObject(confirmedOrder);
                string encryptKey   = _cipherService.Encrypt(objectString);

                _cartSessionService.RemoveCart();

                return(RedirectToAction("ConfirmedOrder", new RouteValueDictionary(
                                            new { controller = "Cart", action = "ConfirmedOrder", confirmedOrder = encryptKey })));
            }
        }
Ejemplo n.º 8
0
        public ActionResult Checkout(ShippingDetailViewModel shippingDetailViewModel)
        {
            if (ModelState.IsValid)
            {
                string userId = User.Identity.GetUserId();
                IEnumerable <CartDetail> cartDetails = cartService.GetByUserID(userId);
                IEnumerable <Book>       books       = bookService.GetAll();
                // Kiem tra tinh hop le cua gio hang
                bool flagValid = true;
                foreach (var cartDetail in cartDetails)
                {
                    Book tmpBook           = cartDetail.Book;
                    int  wareHouseQuantity = (int)bookService.GetByID(tmpBook.ID).Quantity;
                    if (cartDetail.Quantity > wareHouseQuantity)
                    {
                        cartDetail.Quantity = wareHouseQuantity;
                        cartService.UpdateCartDetail(cartDetail);
                        flagValid = false;
                    }
                }
                if (flagValid == false)
                {
                    TempData["errorMessage"] = "Một số sách bạn đặt có số lượng không đủ, chúng tôi đã cập nhật " +
                                               " lại số lượng sách của vài sản phẩm trong giỏ hàng, mời bạn xem và đặt hàng lại";
                    return(RedirectToAction("Index"));
                }
                // Neu hop le
                // create order and orderDetail and update book quantity
                int   totalMoney = cartService.GetTotalMoney(User.Identity.GetUserId());
                Order order      = Mapper.Map <Order>(shippingDetailViewModel);
                order.UserId    = userId;
                order.Status    = (int)StatusOrder.New;
                order.OrderDate = DateTime.Today;
                order.Amount    = totalMoney;
                orderService.CreateOrder(order);



                // send mail to customer
                string subject = "Notification about your order at DTBook";
                ICollection <OrderDetailViewModel> orderDetailViewModels = new List <OrderDetailViewModel>();
                var orderDetails = order.OrderDetails;
                foreach (var item in orderDetails)
                {
                    OrderDetailViewModel tmpOrDeViewModel = Mapper.Map <OrderDetailViewModel>(item);
                    orderDetailViewModels.Add(tmpOrDeViewModel);
                }
                var model = new OrderConfirmEmailModel()
                {
                    Order = order,
                    OrderDetailViewModels = orderDetailViewModels
                };
                var path            = Path.Combine(Server.MapPath("/Helpers/EmailTemplate"), "OrderConfirmTemplate.cshtml");
                var templateSerivce = new TemplateService();
                try
                {
                    string emailHtmlBody = templateSerivce.Parse(System.IO.File.ReadAllText(path), model, null, null);
                    OtherService.SendMail(shippingDetailViewModel.Email, subject, emailHtmlBody);
                }
                catch (Exception ex)
                {
                    Debug.Write("This is inner exeption: " + ex.Message);
                    Debug.Write("This is inner exeption: " + ex.InnerException);
                }
                return(View());
            }
            else
            {
                string errorMessage = "";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        errorMessage += error.ErrorMessage + "<br />";
                    }
                }
                TempData["errorMessage"] = errorMessage;

                return(RedirectToAction("Index"));
            }
        }