public async Task <IActionResult> AddWishListLine([FromBody] ODataActionParameters value) { if (!ModelState.IsValid || value == null) { return(new BadRequestObjectResult(ModelState)); } if (!value.ContainsKey("wishListId") || string.IsNullOrEmpty(value["wishListId"]?.ToString()) || !value.ContainsKey("itemId") || string.IsNullOrEmpty(value["itemId"]?.ToString())) { return(new BadRequestObjectResult(value)); } var wishListId = value["wishListId"].ToString(); var str = value["itemId"].ToString(); var command = Command <AddWishListLineCommand>(); var line = new WishListLineComponent() { ItemId = str }; var wishList = await command.Process(CurrentContext, wishListId, line); return(new ObjectResult(command)); }
public virtual async Task <WishList> Process(CommerceContext commerceContext, WishList wishList, WishListLineComponent line) { WishList result = null; using (CommandActivity.Start(commerceContext, this)) { var context = commerceContext.GetPipelineContextOptions(); result = await _pipeline.Run(new WishListLineArgument(wishList, line), context); } return(result); }
public virtual async Task <WishList> Process(CommerceContext commerceContext, string wishListId, WishListLineComponent line) { WishList result = null; using (CommandActivity.Start(commerceContext, this)) { var context = commerceContext.GetPipelineContextOptions(); var findEntityArgument = new FindEntityArgument(typeof(WishList), wishListId); var wishList = await _getPipeline.Run(findEntityArgument, context) as WishList; if (wishList == null) { await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "EntityNotFound", new object[] { wishListId }, string.Format("Entity {0} was not found.", wishListId)); return(null); } if (wishList.Lines.FirstOrDefault <WishListLineComponent>(c => c.Id == line.Id) == null) { await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "WishListLineNotFound", new object[] { line.Id }, string.Format("WishList line {0} was not found", line.Id)); return(wishList); } result = await _pipeline.Run(new WishListLineArgument(wishList, line), context); return(result); } }
public virtual async Task <WishList> Process(CommerceContext commerceContext, string wishListId, string wishListLineId) { var line = new WishListLineComponent(wishListLineId); return(await Process(commerceContext, wishListId, line)); }
public virtual async Task <WishList> Process(CommerceContext commerceContext, string wishListId, WishListLineComponent line) { using (CommandActivity.Start(commerceContext, this)) { var context = commerceContext.GetPipelineContextOptions(); var findEntityArgument = new FindEntityArgument(typeof(WishList), wishListId, true); var wishList = await _getPipeline.Run(findEntityArgument, context) as WishList; if (wishList == null) { await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "EntityNotFound", new object[] { wishListId }, string.Format("Entity {0} was not found.", wishListId)); return(null); } if (!wishList.IsPersisted) { wishList.Id = wishListId; wishList.Name = wishListId; wishList.ShopName = commerceContext.CurrentShopName(); } var result = await _addToWishListPipeline.Run(new WishListLineArgument(wishList, line), context); await _persistEntityPipeline.Run(new PersistEntityArgument(result), context); return(result); } }
public WishListLineArgument(WishList wishList, WishListLineComponent line) : base(wishList) { Condition.Requires(line).IsNotNull("The line can not be null"); WishList = wishList; Line = line; }