title: C# Using If Statements with enum
body: <p>I want a different viewbag message displayed depending on which option is chosen from a dropdownlist of Enumerators however I'm not sure how to do this. Im using a viewmodel and passing the data through the controller, here is the ViewModel and class, an explanation on how to use if statements with ViewModels/Enumerators would be highly beneficial. I have tried assigning variables but Im realizing that all im doing is saying THIS is THIS, so thats not going to get the data from the Orders Postage enum. Any help and explanations appreciated, still learning.</p>
  
  <p>ViewModel;</p>
  
  <pre><code>{
      public class MyOrdersViewModel
      {
          public int OrderId { get; set; }
          public System.DateTime OrderDate { get; set; }
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string Address { get; set; }
          public string City { get; set; }
          public string PostalCode { get; set; }
          public decimal Total { get; set; }
          public bool HasBeenShipped { get; set; }
          public Postage? PostageList { get; set; }
          public List&lt;MyOrderDetails&gt; Details { get; set; }
      }
  
      public class MyOrderDetails
      {
          public string Title { get; set; }
          public string Colour { get; set; }
          public int Quantity { get; set; }
          public decimal UnitPrice { get; set; }
      }
  }
  </code></pre>
  
  <p>Controller;</p>
  
  <pre><code>        public ActionResult Index(Order order)
          {
              string currentUser = this.User.Identity.GetUserName();
  
              List&lt;T_shirt_Company_v3.ViewModels.MyOrdersViewModel&gt; list = (from o in new TshirtStoreDB().Orders
                      .Where(o =&gt; o.Username == currentUser)
                      .OrderByDescending(o =&gt; o.OrderDate)
                      .Select(o =&gt; new MyOrdersViewModel()
                      {
                          OrderId = o.OrderId,
                          Address = o.Address,
                          FirstName = o.FirstName,
                          LastName = o.LastName,
                          City = o.City,
                          OrderDate = o.OrderDate,
                          PostalCode = o.PostalCode,
                          Total = o.Total,
                          HasBeenShipped = o.HasBeenShipped,
                          PostageList = o.PostageList,
                          Details = (from d in o.OrderDetails
                                     select new MyOrderDetails
                                     {
                                         Colour = d.Product.Colour,
                                         Quantity = d.Quantity,
                                         Title = d.Product.Title,
                                         UnitPrice = d.UnitPrice
                                     }).ToList()
                      }).ToList()
                                                                            select o).ToList();
  
              //@ViewBag.PostageStatus
              //ViewBag.ShippedMessage = list.Where(w =&gt; w.HasBeenShipped).Any() ? "Order has been shipped" : "Order is being processed";
  
              Postage value = Postage.FirstClass;
              Postage value2 = Postage.StandardDelivery;
              Postage value3 = Postage.TwentyFourHour;
  
              if (value == Postage.FirstClass)
              {
                  ViewBag.PostageStatus = ("First Class");
              }
              else
              {
                  ViewBag.PostageStatus = (" Error ");
              }
              if (value2 == Postage.StandardDelivery)
              {
                  ViewBag.PostageStatus = ("Standard Delivery");
              }
              if (value3 == Postage.StandardDelivery)
              {
                  ViewBag.PostageStatus = ("24 hour delivery");
              }
  
  return View(list);
          }
  </code></pre>
  
  <p>Order Class</p>
  
  <pre><code>namespace T_shirt_Company_v3.Models
  {
      //[Bind(Exclude = "OrderId")]
      public partial class Order
      {
          [ScaffoldColumn(false)]
          public int OrderId { get; set; }
  
          [ScaffoldColumn(false)]
          public System.DateTime OrderDate { get; set; }
  
          [ScaffoldColumn(false)]
          [Remote("CheckUserName", "Account")]
          public string Username { get; set; }
  
          [Required]
          [StringLength(16, ErrorMessage = "Your name is too long")]
          [Display(Name = "First Name")]
          public string FirstName { get; set; }
  
          [Required(ErrorMessage = "Your last name is required.")]
          [StringLength(16, ErrorMessage = "Last name is too long.")]
          [Display(Name = "Last Name")]
          public string LastName { get; set; }
  
          [Required(ErrorMessage = "Address is required.")]
          public string Address { get; set; }
  
          [Required(ErrorMessage = "City is required.")]
          public string City { get; set; }
  
          [Required(ErrorMessage = "Postcode is required.")]
          [Display(Name = "Post Code")]
          public string PostalCode { get; set; }
  
          [Required(ErrorMessage = "Country is required.")]
          public string Country { get; set; }
  
          [Required(ErrorMessage = "Phone number is required.")]
          public string Phone { get; set; }
  
          [RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}", ErrorMessage = "Email doesn't look like a valid email address.")]
          public string Email { get; set; }
  
          [System.ComponentModel.DataAnnotations.Compare("Email")]
          [Display(Name = "Confirm your email address")]
          public string EmailConfirm { get; set; }
  
  
          [ScaffoldColumn(false)]
          public string PaymentTransactionId { get; set; }
  
  
          [ScaffoldColumn(false)]
          public bool HasBeenShipped { get; set; }
  
          [ScaffoldColumn(false)]
          //[ReadOnly(true)]
          public decimal Total { get; set; }
  
          [Required]
          [Range(0, 2, ErrorMessage = "Select a delivery method")]
          public Postage? PostageList { get; set; }
  
          public CardDetails cardDetails { get; set; }
          //public List&lt;CardDetails&gt; cardDetails { get; set; }
          public List&lt;OrderDetail&gt; OrderDetails { get; set; }
      }
  
      public enum Postage {[Display(Name = "Standard Delivery - Free")]StandardDelivery, [Display(Name = "First Class Delivery - £4.99")]FirstClass, [Display(Name = "24 Hour Delivery - £9.99")]TwentyFourHour }
  }
  </code></pre>