开发者

finding a member property of an item in an array

开发者 https://www.devze.com 2023-03-16 01:02 出处:网络
I\'ve passed in the whole sale object into this function. In that sale object, there are many childs e.g. saleOrderItem, Payment, User...

I've passed in the whole sale object into this function. In that sale object, there are many childs e.g. saleOrderItem, Payment, User...

sale.payment is an array

Question: 1) How do I get the CodeNo from the `sale.payment' object? (as payment is an array)

2) How to get the sale.payment.CourseByTutor.TutorId (as payment is an array)

  public static object GetSalesDataBySaleOrderID(SaleOrder sale)
        {
            return sale.saleOrderItem
                       .Where(s => s != null)
                       .Select(s => new { 
                                          Id = s.Id,
                                          Username = sale.User.GetSingleUserById(s.UserId).Name,
                                          Amount = s.Amount,
                                          CodeNo = s.SaleOrder.payment.First().CodeNo,
                                          TutorName = sale.User.GetSingleUserById(s.SaleOrder.payment.FirstOrDefault().CourseByTutor.TutorId).Name,
                                        })
                       .ToList();
        }

Here is how i bind the value to the object

 private void SaveValueToObject()
    {
        saleOrder.UserId = UserInfo.Id;
        saleOrder.Date = DateTime.Now;            

        for (int i = 0; i < dgSale.Rows.Count; i++)
        {
            SaleOrderItem SaleItem = new SaleOrderItem();
            SaleItem.InventoryTypeId = Convert.ToInt32(dgSale.Rows[i].Cells["inventoryTypeId"].Value);
            SaleItem.InventoryOrCourseId = Convert.ToInt32(dgSale.Rows[i].Cells["inventoryId"].Value);
            SaleItem.Qty = Convert.ToInt32(dgSale.Rows[i].Cells["qty"].Value);
            SaleItem.Amount = Convert.ToDecimal(dgSale.Rows[i].Cells["total"].Value);
            SaleItem.UserId = Convert.ToInt32(dgSale.Rows[i].Cells["userId"].Value);
            SaleItem.Discount = Convert.ToDecimal(dgSale.Rows[i].Cells["discount"].Value);
            SaleItem.Remarks = (dgSale.Rows[i].Cells["remark"].Value == null) ? "" : dgSale.Rows[i].Cells["remark"].Value.ToString();
            SaleItem.Status = (int)SaleOrderStatus.Active;
            saleOrder.saleOrderItem[i] = SaleItem;                


            Payment p = new Payment();
            p.PayType = Convert.ToInt32(dgSale.Rows[i].Cells["payType"].Value);
            p.Code = (int)PaymentCode.RCT; // For Receipt prefix
            p.CodeNo = p.GetNewReceiptNo(p.Code); //Check if it is receipt, if yes, Get last Receipt No + 1
            p.UserId = (txtUserId.Text == string.Empty) ? 0 : Convert.ToInt32(txtUserId.Text);
            p.Amount = Convert.ToDecimal(dgSale.Rows[i].Cells["total"].Value);
            p.Remark = (dgSale.Rows[i].Cells["remark"].Value == null) ? "" : dgSale.Rows[i].Cells["remark"].Value.ToString();
            p.PaymentMethodId = saleOrder.PaymentMethodId;
            p.DateIssue = saleOrder.Date;

            p.CourseByTutor.TutorI开发者_如何学JAVAd = Convert.ToInt32(dgSale.Rows[i].Cells["tutorId"].Value);


            saleOrder.payment[i] = p;
        }
    }


I have a workaround and solved this question by adding the desired properties e.g. TutorId in the sale.saleOrderItem class. Thus making the direct access to the sale.SaleOrderItem.TutorId.
This sound stupid but it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号