public async Task <IEnumerable <VmProductCostDetails> > Search_VmCostProductInfo([FromBody] VmSearchProductCost vm) { List <VmProductCostDetails> VmProductCostDetailData = new List <VmProductCostDetails>(); var dataReceivedFromDatabase = await(from p in db.Product join pc in db.ProductCostInfo on p.ProductId equals pc.ProductId join pct in db.ProductCategory on pc.ProductCategoryId equals pct.ProductCategoryId join b in db.Brand on pc.BrandId equals b.BrandId join em in db.Employee on pc.EmployeeId equals em.EmployeeId //where p.ProductName.ToLower().ToString() == vm.ProductName.ToLower().ToString() || pct.ProductCategoryName.ToLower().ToString() == vm.ProductCategoryName.ToLower().ToString() || b.BrandName.ToLower().ToString() == vm.BrandName.ToLower().ToString() || em.EmployeeName.ToLower().ToString() == vm.EmployeeName.ToLower().ToString() || em.EmployeeMobileNo.ToLower().ToString() == vm.EmployeeMobileNo.ToLower().ToString() where em.EmployeeMobileNo.StartsWith(vm.EmployeeMobileNo) || em.EmployeeMobileNo.Contains(vm.EmployeeMobileNo) || em.EmployeeMobileNo == vm.EmployeeMobileNo select new { b.BrandId, b.BrandName, em.EmployeeId, em.EmployeeName, em.EmployeeMobileNo, em.EmployeeAddress, p.ProductId, p.ProductName, p.ProductByteImage, p.ProductPicturePath, pct.ProductCategoryId, pct.ProductCategoryName, pc.ProductCostInfoId, pc.ProductSize, pc.UnitPrice, pc.Quantity, pc.TransportCost, pc.Discount, pc.DateOfOrder, pc.Subtotal, pc.GrandTotal, pc.CurrentPayment, pc.DueAmount } ).ToListAsync(); if (dataReceivedFromDatabase.Count() > 0) { foreach (var data in dataReceivedFromDatabase) { VmProductCostDetails vmData = new VmProductCostDetails(); vmData.BrandId = data.BrandId; vmData.BrandName = data.BrandName; vmData.CurrentPayment = data.CurrentPayment; vmData.DateOfOrder = data.DateOfOrder; vmData.Discount = data.Discount; vmData.DueAmount = data.DueAmount; vmData.EmployeeId = data.EmployeeId; vmData.EmployeeName = data.EmployeeName; vmData.EmployeeMobileNo = data.EmployeeMobileNo; vmData.EmployeeAddress = data.EmployeeAddress; vmData.GrandTotal = data.GrandTotal; vmData.ProductCategoryId = data.ProductCategoryId; vmData.ProductCategoryName = data.ProductCategoryName; vmData.ProductCostInfoId = data.ProductCostInfoId; vmData.ProductId = data.ProductId; vmData.ProductName = data.ProductName; vmData.ProductByteImage = data.ProductByteImage; vmData.ProductPicturePath = data.ProductPicturePath; vmData.ProductSize = data.ProductSize; vmData.Quantity = data.Quantity; vmData.Subtotal = data.Subtotal; vmData.TransportCost = data.TransportCost; vmData.UnitPrice = data.UnitPrice; VmProductCostDetailData.Add(vmData); } } return(VmProductCostDetailData); }
public async Task <ActionResult <IEnumerable <VmProductCostDetails> > > GetProductEntryList() { List <VmProductCostDetails> vmList = new List <VmProductCostDetails>(); var productCostList = await _db.ProductEntry.ToListAsync(); foreach (var data in productCostList) { var emp = await _db.Employee.Where(e => e.EmployeeId == data.EmployeeId).Select(e => new { e.EmpAddress, e.EmployeeId, e.EmpMobileNo, e.EmpName, e.GenderId, e.ReligionId, e.ThanaId }).FirstOrDefaultAsync(); var category = await _db.Category.Where(c => c.CategoryId == data.CategoryId).Select(c => new { c.CategoryId, c.CategoryName, c.BrandId }).FirstOrDefaultAsync(); var brand = await _db.Brand.Where(b => b.BrandId == category.BrandId).Select(b => new { b.BrandId, b.BrandName, b.ProductId }).FirstOrDefaultAsync(); var product = await _db.Product.Where(p => p.ProductId == brand.ProductId).Select(p => new { p.ProductId, p.ProductName }).FirstOrDefaultAsync(); VmProductCostDetails vm = new VmProductCostDetails() { ProductEntryId = data.ProductEntryId, VoucherNumber = data.VoucherNumber, Quantity = data.Quantity, UnitPrice = data.UnitPrice, Discount_Percentage = data.Discount_Percentage, SubTotalCost = data.SubTotalCost, DateOfEntry = data.DateOfEntry, CategoryId = category.CategoryId, CategoryName = category.CategoryName, BrandId = brand.BrandId, BrandName = brand.BrandName, ProductId = product.ProductId, ProductName = product.ProductName, EmployeeId = emp.EmployeeId, EmpName = emp.EmpName, }; vmList.Add(vm); } return(vmList); }