ToString() public method

public ToString ( ) : string
return string
Beispiel #1
0
 public IActionResult Order(ContactsViewModel order)
 {
     if (ModelState.IsValid)
     {
         Cart cart = HttpContext.Session.Get <Cart>("cart");
         if (cart == null)
         {
             return(RedirectToAction("List", "Records"));
         }
         Order newOrder = new Order()
         {
             Name    = order.Name,
             Surname = order.Surname,
             Email   = order.Email,
             Adress  = order.Address,
             Sum     = cart.Total,
             Id      = Guid.NewGuid().ToString(),
             Cart    = cart.ToString()
         };
         orderRepository.Create(newOrder);
         return(RedirectToAction(nameof(Payment), new { orderId = newOrder.Id, sum = newOrder.Sum }));
     }
     else
     {
         return(View(order));
     }
 }
 public ActionResult <Response> PutCart([FromRoute] int id, [FromBody] Cart cart)
 {
     try
     {
         int userid  = string.IsNullOrEmpty(HttpContext.Session.GetString("userid")) ? 1 : int.Parse(HttpContext.Session.GetString("userid"));
         var oldCart = appDbContext.Carts.SingleOrDefault(p => p.Id == id && p.UserId == userid);
         if (oldCart != null)
         {
             oldCart.ProductId = cart.ProductId;
             oldCart.Quantity  = cart.Quantity;
             oldCart.Price     = cart.Price;
             appDbContext.SaveChangesAsync();
             return(new Response(oldCart, 200, "Updated Successfully"));
         }
         else
         {
             return(new Response(null, 400, "No Data Found for Cart"));
         }
     }
     catch (Exception ex)
     {
         logger.LogError(ex, cart.ToString());
         return(new Response(null, 404, ex.Message));
     }
 }
 public ActionResult <Response> PostCart([FromBody] Cart cart)
 {
     try
     {
         int userid = string.IsNullOrEmpty(HttpContext.Session.GetString("userid")) ? 1 : int.Parse(HttpContext.Session.GetString("userid"));
         cart.UserId = userid;
         appDbContext.Carts.Add(cart);
         appDbContext.SaveChangesAsync();
         return(new Response(cart));
     }
     catch (Exception ex)
     {
         logger.LogError(ex, cart.ToString());
         return(new Response(null, 404, ex.Message));
     }
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            try
            {
                ICartService mCartService = new CartService("Fake");
                //Create Cart
                int cartID = mCartService.CreateCartNew();

                //Add fake item to cart.
                mCartService.AddCartItem(1, 3);
                mCartService.AddCartItem(2, 3);
                mCartService.AddCartItem(3, 5);
                mCartService.AddCartItem(4, 3);
                mCartService.AddCartItem(5, 3);
                mCartService.AddCartItem(6, 3);
                mCartService.AddCartItem(7, 6);
                mCartService.AddCartItem(8, 6);
                mCartService.AddCartItem(9, 6);
                mCartService.AddCartItem(10, 6);

                //Process cart.
                Cart mCart = mCartService.CheckOutCart(cartID);

                //Print cart detail on screen.
                foreach (var item in mCart.LineItems)
                {
                    Console.WriteLine(item.ToString());
                }
                Console.WriteLine("----------------------------------------");
                Console.WriteLine(mCart.ToString());

                Console.ReadKey();
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
        }
Beispiel #5
0
        public void NotifyCustomerOrderCreated(Cart cart)
        {
            string customerEmail = cart.CustomerEmail;

            if (!String.IsNullOrEmpty(customerEmail))
            {
                using (var message = new MailMessage("*****@*****.**", customerEmail))
                    using (var client = new SmtpClient("localhost"))
                    {
                        message.Subject = "Your order placed on " + DateTime.Now.ToString();
                        message.Body    = "Your order details: \n " + cart.ToString();

                        try
                        {
                            client.Send(message);
                        }
                        catch (Exception ex)
                        {
                            //Logger.Error("Problem sending notification email", ex);
                        }
                    }
            }
        }
Beispiel #6
0
 public override string ToString()
 {
     return(string.Format("\n{0}\n{1}\n", Cart.ToString(), ReturnUrl.ToString()));
 }
 protected override string HandleInternal(string command, string commandParam, Cart cart)
 {
     return(cart.ToString());
 }