public ActionResult SendOrder(int id) { Tbl_Orders tbl = _unitOfWork.GetRepositoryInstance <Tbl_Orders>().GetFirstorDefault(id); tbl.OrderStatus = "Shipped"; _unitOfWork.GetRepositoryInstance <Tbl_Orders>().Update(tbl); Tbl_Members tbl_Members = _unitOfWork.GetRepositoryInstance <Tbl_Members>().GetFirstorDefault((int)tbl.MemberId); Gmail.SendEmail(tbl_Members, tbl); return(RedirectToAction("Orders")); }
/// <summary> /// </summary> /// <returns></returns> //ERRRRRRRRRRRRRRRRRRRRRRRRRRRORRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR public ActionResult Order() { if (Session["Orders"] != null) { List <Tbl_Cart> CartList = new List <Tbl_Cart>(); Tbl_Orders order; foreach (var item in (List <Tbl_Cart>)Session["Orders"]) { order = new Tbl_Orders() { MemberID = (int)item.MemberId, OrderStatues = false, ProductId = (int)item.ProductId, Quantity = (int)item.Quantity }; CartList.Add(item); _unitOfWork.GetRepositoryInstance <Tbl_Orders>().Add(order); } foreach (var cart in CartList) { var car = db.Tbl_Cart.Find(cart.CartId); car.OrderStatues = true; db.Entry(car).State = EntityState.Modified; db.SaveChanges(); } ViewBag.Orders = "Orders Are Sent To Seller Succesfully"; return(RedirectToAction("MyOrders")); } return(RedirectToAction("MyOrders")); }
//Send email to confirm that the order is shipped public static void SendEmail(Tbl_Members member, Tbl_Orders order) { MailMessage mm = new MailMessage("*****@*****.**", member.EmailId); mm.Body = "Hi " + member.FristName + " " + member.LastName + "\n \n" + "You order on PepeSurfShop was already shipped \n \n " + "\n" + "Now It's up to the postal service to carry your products ! \n" + "\n" + "\n" + "Order ID : " + order.OrderId + "\n" + "Your order stauts : " + order.OrderStatus + "\n" + "\n" + "\n" + "Please do not hesitate to contact us for any issue ! \n" + "\n" + "\n" + "Best regards\n" + "PepeSurfShop\n" + ""; mm.Subject = "Your PepeSurfShop Order Shipped"; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; NetworkCredential nc = new NetworkCredential("*****@*****.**", "Qwerty.1234"); smtp.UseDefaultCredentials = true; smtp.Credentials = nc; smtp.Send(mm); }
public ActionResult CreateOrder(CreateOrderViewModel orderViewModel) { if (orderViewModel != null && ModelState.IsValid) { dbMyOnlineShoppingEntities db = new dbMyOnlineShoppingEntities(); var mem = _unitOfWork.GetRepositoryInstance <Tbl_Members>().GetAllRecords(); var maxMemberId = 0; foreach (var item in mem) { if (item.MemberId > maxMemberId) { maxMemberId = item.MemberId + 1; } } Tbl_Members person = new Tbl_Members(); person.FristName = orderViewModel.Member.FristName; person.LastName = orderViewModel.Member.LastName; person.MemberId = maxMemberId; person.CreatedOn = DateTime.Now; person.EmailId = orderViewModel.Member.EmailId; person.IsActive = true; person.IsDelete = false; person.Password = "******"; person.ModifiedOn = DateTime.Now; _unitOfWork.GetRepositoryInstance <Tbl_Members>().Add(person); var shippingDet = _unitOfWork.GetRepositoryInstance <Tbl_ShippingDetails>().GetAllRecords(); var maxShipId = 0; foreach (var item in shippingDet) { if (item.ShippingDetailId > maxShipId) { maxShipId = item.ShippingDetailId + 1; } } var orders = _unitOfWork.GetRepositoryInstance <Tbl_Orders>().GetAllRecords(); var maxOrderId = 0; foreach (var item in orders) { if (item.OrderId > maxOrderId) { maxOrderId = item.OrderId + 1; } } Tbl_ShippingDetails shippingDetails = new Tbl_ShippingDetails(); shippingDetails.ShippingDetailId = maxShipId; shippingDetails.Adress = orderViewModel.ShippingDetails.Adress; shippingDetails.City = orderViewModel.ShippingDetails.City; shippingDetails.ZipCode = orderViewModel.ShippingDetails.ZipCode; shippingDetails.Country = orderViewModel.ShippingDetails.Country; shippingDetails.State = orderViewModel.ShippingDetails.State; shippingDetails.MemberId = maxMemberId; string AmountPaid = Session["SesTotal"].ToString(); shippingDetails.AmountPaid = Decimal.Parse(AmountPaid); orderViewModel.ShippingDetails.AmountPaid = shippingDetails.AmountPaid; shippingDetails.PaymentType = "Cash"; _unitOfWork.GetRepositoryInstance <Tbl_ShippingDetails>().Add(shippingDetails); Tbl_Orders order = new Tbl_Orders(); order.MemberId = person.MemberId; order.OrderStatus = "First Step"; order.ShippingDetailsId = shippingDetails.ShippingDetailId; order.OrderId = maxOrderId; _unitOfWork.GetRepositoryInstance <Tbl_Orders>().Add(order); List <Item> cart = (List <Item>)Session["cart"]; foreach (var item in cart) { if (item.Quantity > 0) { Tbl_OrderProducts orderProducts = new Tbl_OrderProducts(); orderProducts.ProductId = item.Product.ProductId; orderProducts.Quantity = item.Quantity; orderProducts.OrderId = order.OrderId; _unitOfWork.GetRepositoryInstance <Tbl_OrderProducts>().Add(orderProducts); } } //The string with the products that will be sent to the customer string products = "------------------------------------------------------------------------------------------\n" + "|Qty.x Price| Name \n" + "------------------------------------------------------------------------------------------\n" ; foreach (Item item in (List <Item>)Session["cart"]) { int lineTotal = Convert.ToInt32(item.Quantity * item.Product.Price); string product = "| " + item.Quantity + " x " + item.Product.Price + " | " + item.Product.ProductName + ":\n " + "------------------------------------------------------------------------------------------\n"; products = string.Concat(products, product); } Gmail.SendEmail(orderViewModel, products); return(RedirectToAction("PayOrder", "Home")); } //if the Model was not valid render again the page return(RedirectToAction("CreateOrder", "Home")); }