public async Task <IHttpActionResult> GetDefaultCoupons(ClientOrderModel order) { if (!this.ModelState.IsValid) { Logger.Current.LogWarning("Orders.GetDefaultCoupons: invalid model state"); return(this.BadRequest(this.ModelState)); } List <CouponeModel> defaultCoupons = new List <CouponeModel>(); IIdentity currentIdentity = this.User.Identity; bool isAuthenticated = currentIdentity.IsAuthenticated; bool isLoyalCustomer = false; if (isAuthenticated) { string currentUserId = currentIdentity.GetUserId(); using (ApplicationUserManager userManager = Startup.UserManagerFactory()) { isLoyalCustomer = await userManager.IsInRoleAsync(currentUserId, "LoyalCustomer"); } } //Volume discounts can be added here CouponesProvider couponesProvider = new CouponesProvider(); IEnumerable <CouponeModel> coupones = await couponesProvider.GetCoupons(isAuthenticated, isLoyalCustomer); return(this.Ok(coupones)); }
public async Task <IHttpActionResult> Validate(ClientOrderModel order) { if (order == null) { Logger.Current.LogWarning("Orders.Validate: null"); return(this.BadRequest("Empty order")); } if (!this.ModelState.IsValid) { Logger.Current.LogWarning("Orders.Validate: invalid model state"); return(this.BadRequest(this.ModelState)); } if (order.Items.Count() == 0) { Logger.Current.LogWarning("Orders.Validate: no items"); return(this.BadRequest("Empty order")); } OrderItemsGrouper itemsGrouper = new OrderItemsGrouper(); IList <OrderedItemModel> normalizedItems = itemsGrouper.NormalizeOrderedItems(order.Items.ToList()); if (normalizedItems == null) { Logger.Current.LogWarning("Orders.Validate: grouping error"); return(this.BadRequest("Different prices of the same item")); } OrderValidator orderValidator = new OrderValidator(); bool isOrderValid = await orderValidator.ValidateOrderItems(normalizedItems); if (!isOrderValid) { Logger.Current.LogWarning("Orders.Validate: invalid quantities"); return(this.BadRequest("Invalid quantities")); } return(this.Ok()); }