public async Task <Response> Edit(CommodityRequestCheckoutViewModel model) { var checkout = await _repository.GetById(model.Id); var updatedItems = _mapper.Map <List <CheckoutedLineItem> >(model.LineItems); var selectedCommodities = _commodityRepository.GetListByIds(updatedItems.Select(x => x.CommodityId).ToList()); updatedItems.ForEach(x => { x.Commodity = selectedCommodities.First(c => c.Id == x.CommodityId); }); checkout.UpdateItems(updatedItems); return(Response.Success()); }
private void LoadRefrencedCommidities(CommodityRequestForm arg) { if (arg.LineItems.All(x => x.Commodity == null)) { _commodityRepository.GetListByIds(arg.LineItems.Select(x => x.CommodityId).ToList()).ForEach(x => { foreach (var lineItem in arg.LineItems) { if (lineItem.CommodityId == x.Id) { lineItem.Commodity = x; } } }); } }