public IEnumerable <ValidationResult> Validate(ValidationContext valContext) { foreach (var item in OrderItems) { if (OrderItems.Count(oi => oi.ProductId == item.ProductId) > 1) { yield return(new ValidationResult("Each product can be chosen just once.")); } } }
private bool ValidateFields() { if (OrderItems == null || OrderItems.Count <ItemOptionsClass>() == 0) { return(false); } if (SelectedCustomer == null) { return(false); } // the setter for OrderNum sets the field to "" if it doesn't parse if (_orderNum.Length == 0) { return(false); } return(true); }
private bool CreateOrder() { if (OrderItems != null && OrderItems.Count() > 0) { List <OrderItem> orderItems = new List <OrderItem>(); foreach (var product in OrderItems) { OrderItem item = ProductViewModelToOrderItem(product); orderItems.Add(item); } Order.OrderItems = orderItems; Order.OrderDate = DateTime.UtcNow; Order.RegisteringEmployeeId = ((Employee)cbShopEmployees.SelectedItem).Id; Order.LocationId = ShopGlobals.Location.Id; Order.ShopId = ShopGlobals.Shop.Id; if (cbLocationCustomers.SelectedItem != null) { Customer cust = cbLocationCustomers.SelectedItem as Customer; if (cust.Id != ObjectId.Empty) { Order.CustomerId = cust.Id; } Order.Customer = new OrderCustomer() { Address = cust.Address, Occupation = cust.Occupation, Name = cust.Name }; } return(true); } return(false); }