locked
When i am getting records i got these errors by using RestApi and Code First Can you please some one help me RRS feed

  • Question

  • User-1945483459 posted

    Error CS0103 The name 'query' does not exist in the current context.
    Error CS0103 The name 'First' does not exist in the current context.
    Error CS0103 The name 'query.First' does not exist in the current context.
    Error CS0161 'PurchaseOrderService.GetAllProductstatusdetails()':
    Error CS1519 Invalid token '(' in class, struct, or interface member declaration
    Error CS1519 Invalid token '(' in class, struct, or interface member declaration
    Error CS1519 Invalid token 'return' in class, struct, or interface member declaration
    Error CS1513 } expected

    This is my Purchaseorderservices.cs page.

    using QFT_POMS_SVC.Domain.POMS;
    using System.Collections.Generic;
    using System.Linq;

    namespace QFT_POMS_SVC.Services.POMS
    {
    public class PurchaseOrderService : IPurchaseOrderService
    {
    ProductStatusEntities entities = new ProductStatusEntities();
    private DBMapper _dbContext;
    private Result _result;
    private object query;

    public PurchaseOrderService()
    {
    _dbContext = new DBMapper();
    _result = new Result();
    }
    public IList<Distributor> GetAllDistributorsOp()
    {
    var query = from d in _dbContext.DistributorRepository select d;
    return query.ToList();
    }
    public IList<PurchaseOrder> GetAllPOByDistributorIdOp(int DistributorId)
    {
    var query = from po in _dbContext.PurchaseOrderRepository
    where po.DistributorId == DistributorId
    select po;

    return query.ToList();
    }

    public PurchaseOrder GetPODetailsOp(int PurchaseOrderId)
    {
    var query = from po in _dbContext.PurchaseOrderRepository
    where po.Id == PurchaseOrderId
    select po;

    return query.First();
    }

    private void UpdatePurchaseOrderItems(int purchaseorderid, List<PurchaseOrderItem> items)
    {
    foreach (var item in items)
    {
    var _item = _dbContext.PurchaseOrderItemsRepository.Where(po => po.Id == item.Id).First();
    _item.QtyReceived = item.QtyReceived;
    _item.Received = item.Received;
    _item.UnitCostReceived = item.UnitCostReceived;
    _item.Discontinued = item.Discontinued;
    }
    _dbContext.SaveChanges();
    }

    public Result UpdatePurchaseOrderOp(PurchaseOrder po)
    {
    var _purchaseOrder = GetPODetailsOp(po.Id);
    _purchaseOrder.deleted = po.deleted;
    _purchaseOrder.InvoiceDate = po.InvoiceDate;
    _purchaseOrder.InvoiceDueDate = po.InvoiceDueDate;
    _purchaseOrder.InvoiceNumber = po.InvoiceNumber;
    //_purchaseOrder.items.Clear();

    //_purchaseOrder.items = po.items;
    _purchaseOrder.PORcvdAmount = po.PORcvdAmount;

    UpdatePurchaseOrderItems(po.Id, po.items);


    _dbContext.SaveChanges();
    return _result;
    }

    public List<ProductStatusEntities> GetAllProductstatusdetails()
    {
    var query = from orditem in _dbContext.OrderItemRepository
    from p in _dbContext.ProductRepository
    from dpm in _dbContext.DistributorProductMappingRepository
    from pwi in _dbContext.ProductWarehouseInventoryRepository
    where
    p.ProductTypeId == orditem.ProductId &&
    dpm.ProductId == pwi.ProductId &&
    dpm.ProductId == orditem.ProductId &&
    orditem.Order.OrderStatusId == 20
    group new { orditem, p, dpm.Distributor, dpm, pwi } by new
    {
    orditem.ProductId,
    orditem.OrderId,
    p.Name,
    p.ProductTypeId,
    Column1 = dpm.Distributor.Name,
    dpm.StockStatus,
    dpm.UnitPrice,
    pwi.StockQuantity,
    Column2 = p.StockQuantity
    } into g
    select new
    {
    g.Key.OrderId,
    g.Key.ProductId,
    productname = g.Key.Name,
    g.Key.UnitPrice,
    Distributorname = g.Key.Column1,
    orderquantity = (int?)g.Sum(p => p.orditem.Quantity),
    TotalQuantity = (int?)g.Sum(p => p.pwi.StockQuantity + p.dpm.StockStatus + p.p.StockQuantity); }

    return query.First();
    }

    }

    Thursday, June 20, 2019 6:10 AM

All replies

  • User-821857111 posted

    Kondalrao

    private object query;

    Get rid of that line. Then add a } to the end of the file. See how many of the errors that removes.

    Thursday, June 20, 2019 10:28 AM
  • User303363814 posted

    Those errors don't seem to match the code you have shown.  Which is the actual line that the error refers to.  (The line 'private object query' seems to be superfluous and has nothing to do with the rest of the code as that variable is not referenced anywhere)

    The general procedure for fixing compilation errors is

    1. double-click on the first error.
    2. Fix that error
    3. Recompile
    4. If there are errors then go to step 1

    So, which is your first error?  Which line of code does it refer to?  If you can't work it out then show us as much of the error message as possible, the actual line referenced by the error message (double-click on the error to go to the correct line - don't guess!).

    The absolute best thing you can do for us and for yourself is to make a small example program that could be compiled by anyone which shows the problem - a 'reproducer'.  You can sometimes make a reproducer by making a copy of your code and deleting as much code as possible until you are left with the smallest amount of code which exhibits the problem.

    (When you add code to a post use the "Insert/edit code sample" button on the editor toolbar.  It looks like this ===>   {I}  

    Thursday, June 20, 2019 11:22 PM