public async Task <IActionResult> GetItemList(FilterationListViewModel model) { try { //to get userid from access token string UId = User.Claims.First(c => c.Type == "UserID").Value; var user = await _userManager.FindByIdAsync(UId); string parentUserId = user.Id; if (User.IsInRole(Constants.isSubAdmin)) { parentUserId = user.ParentUserId; } var userstatus = user.UserStatus; var itemList = _managementService.GetItemList(model, parentUserId); if (itemList == null) { return(Ok(new { status = StatusCodes.Status404NotFound, success = false, message = ResponseMessages.msgNotFound + "item.", userstatus = false })); } return(Ok(new { status = StatusCodes.Status200OK, success = true, message = "item" + ResponseMessages.msgListFoundSuccess, userstatus, itemList })); } catch (Exception ex) { return(Ok(new { status = StatusCodes.Status500InternalServerError, success = false, message = ResponseMessages.msgSomethingWentWrong + ex.Message, userstatus = false })); } }
public ResponseModel <CustomerListViewModel> GetCustomerList(FilterationListViewModel model, string UserId) { if (db != null) { var source = (from c in db.Customers join cntry in db.Countries on c.CountryId equals cntry.CountryId into ctryGroup from cntry in ctryGroup.DefaultIfEmpty() join s in db.States on c.StateId equals s.StateId into sGroup from s in sGroup.DefaultIfEmpty() where c.UserId == UserId && (c.IsDeleted == false || c.IsDeleted == null) orderby c.CustomerId descending select new CustomerListViewModel { CustomerId = c.CustomerId, FirstName = c.FirstName, LastName = c.LastName, BussinessName = c.BussinessName, Phone = c.Phone, Fax = c.Fax, Mobile = c.Mobile, CountryName = cntry.Name, StateName = s.Name, City = c.City, Postalcode = c.Postalcode, Address1 = c.Address1, PersonalEmail = c.PersonalEmail, BussinessEmail = c.BussinessEmail, Gender = c.Gender, Dob = (c.Dob != null) ? c.Dob.Value.ToString("dd/MM/yyyy") : "", Gstin = c.Gstin, AccountNumber = c.AccountNumber.ToString(), PosoNumber = c.PosoNumber, Website = c.Website, IsActive = Convert.ToBoolean(c.IsActive) }).AsQueryable(); // searching if (!string.IsNullOrWhiteSpace(model.searchQuery)) { var search = model.searchQuery.ToLower(); source = source.Where(x => x.FirstName.ToLower().Contains(search) || x.LastName.ToLower().Contains(search) || x.Phone.ToLower().Contains(search) || x.Fax.ToLower().Contains(search) || x.Mobile.ToLower().Contains(search) ); } // Get's No of Rows Count int count = source.Count(); // Parameter is passed from Query string if it is null then it default Value will be pageNumber:1 int CurrentPage = model.pageNumber; // Parameter is passed from Query string if it is null then it default Value will be pageSize:20 int PageSize = model.pageSize; // Display TotalCount to Records to User int TotalCount = count; // Calculating Totalpage by Dividing (No of Records / Pagesize) int TotalPages = (int)Math.Ceiling(count / (double)PageSize); // Returns List of Customer after applying Paging var items = source.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList(); // if CurrentPage is greater than 1 means it has previousPage var previousPage = CurrentPage > 1 ? "Yes" : "No"; // if TotalPages is greater than CurrentPage means it has nextPage var nextPage = CurrentPage < TotalPages ? "Yes" : "No"; // Returing List of Customers Collections ResponseModel <CustomerListViewModel> obj = new ResponseModel <CustomerListViewModel>(); obj.totalCount = TotalCount; obj.pageSize = PageSize; obj.currentPage = CurrentPage; obj.totalPages = TotalPages; obj.previousPage = previousPage; obj.nextPage = nextPage; obj.searchQuery = string.IsNullOrEmpty(model.searchQuery) ? "no parameter passed" : model.searchQuery; obj.dataList = items.ToList(); return(obj); } return(null); }
public ResponseModel <ItemViewModel> GetItemList(FilterationListViewModel model, string UserId) { if (db != null) { //Return Lists var source = (from c in db.Items where c.UserId == UserId && (c.IsDeleted == false || c.IsDeleted == null) orderby c.ItemId descending select new ItemViewModel { ItemId = c.ItemId, Name = c.Name, Description = c.Description, Quantity = c.Quantity, Price = c.Price, Tax = c.Tax, UserId = c.UserId }).AsQueryable(); //Search Parameter With null checks if (!string.IsNullOrWhiteSpace(model.searchQuery)) { var search = model.searchQuery.ToLower(); source = source.Where(x => x.Name.ToLower().Contains(search) || x.Description.ToLower().Contains(search) || x.Quantity.ToString().Contains(search) || x.Price.ToString().Contains(search) || x.Tax.ToString().Contains(search) ); } // Get's No of Rows Count int count = source.Count(); // Parameter is passed from Query string if it is null then it default Value will be pageNumber:1 int CurrentPage = model.pageNumber; // Parameter is passed from Query string if it is null then it default Value will be pageSize:20 int PageSize = model.pageSize; // Display TotalCount to Records to User int TotalCount = count; // Calculating Totalpage by Dividing (No of Records / Pagesize) int TotalPages = (int)Math.Ceiling(count / (double)PageSize); // Returns List of Customer after applying Paging var items = source.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList(); // if CurrentPage is greater than 1 means it has previousPage var previousPage = CurrentPage > 1 ? "Yes" : "No"; // if TotalPages is greater than CurrentPage means it has nextPage var nextPage = CurrentPage < TotalPages ? "Yes" : "No"; // Returing List of Customers Collections ResponseModel <ItemViewModel> obj = new ResponseModel <ItemViewModel>(); obj.totalCount = TotalCount; obj.pageSize = PageSize; obj.currentPage = CurrentPage; obj.totalPages = TotalPages; obj.previousPage = previousPage; obj.nextPage = nextPage; obj.searchQuery = string.IsNullOrEmpty(model.searchQuery) ? "no parameter passed" : model.searchQuery; obj.dataList = items.ToList(); return(obj); } return(null); }
public ResponseModel <InvoiceListViewModel> GetInvoiceList(FilterationListViewModel model, string UserId) { if (db != null) { //Return Lists var source = (from i in db.Invoices join c in db.Currencies on i.CurrencyId equals c.CurrencyId into cGroup from c in cGroup.DefaultIfEmpty() join cst in db.Customers on i.CustomerId equals cst.CustomerId into cstGroup from cst in cstGroup.DefaultIfEmpty() where i.UserId == UserId && (i.IsDeleted == false || i.IsDeleted == null) orderby i.InvoiceId descending select new InvoiceListViewModel { InvoiceId = i.InvoiceId, Title = i.Title, Description = i.Description, InvoiceNumber = i.InvoiceNumber, PosoNumber = i.PosoNumber, Date = (i.Date != null) ? i.Date.ToString("dd/MM/yyyy") : "", DueDate = (i.DueDate != null) ? i.DueDate.ToString("dd/MM/yyyy") : "", ItemList = JsonConvert.DeserializeObject <List <InvoiceItemsViewModel> >(i.ItemList), Status = i.Status, Type = i.Type, Subtotal = i.Subtotal, Tax = i.Tax, Total = i.Total, IsSent = i.IsSent, UserId = i.UserId, Notes = !string.IsNullOrWhiteSpace(i.Notes) ? i.Notes : "", TermsAndConditions = !string.IsNullOrWhiteSpace(i.TermsAndConditions) ? i.TermsAndConditions : "", ConvertedDate = (i.ConvertedDate != null) ? i.ConvertedDate.Value.ToString("dd/MM/yyyy") : "", IsPaid = i.IsPaid, PaymentDate = (i.PaymentDate != null) ? i.PaymentDate.Value.ToString("dd/MM/yyyy") : "", PaymentMode = (i.PaymentMode != null) ? i.PaymentMode : "", CurrencyId = i.CurrencyId, CurrencyName = c.Name, CurrencyCode = c.Code, CurrencySymbol = c.Symbol, CustomerId = i.CustomerId, FirstName = cst.FirstName, LastName = cst.LastName, BussinessName = cst.BussinessName, Phone = cst.Phone, Mobile = cst.Mobile, Address1 = cst.Address1, PersonalEmail = cst.PersonalEmail, BussinessEmail = !string.IsNullOrWhiteSpace(cst.BussinessEmail) ? cst.BussinessEmail : "", Gstin = !string.IsNullOrWhiteSpace(cst.Gstin) ? cst.Gstin : "", AccountNumber = cst.AccountNumber.ToString(), Website = !string.IsNullOrWhiteSpace(cst.Website) ? cst.Website : "" }).AsQueryable(); //Filter Parameter With null checks if (!string.IsNullOrEmpty(model.filterBy)) { var filterBy = model.filterBy.ToLower(); source = source.Where(m => m.Type.ToLower().Contains(filterBy) || m.Status.ToLower().Contains(filterBy)); } //Search Parameter With null checks if (!string.IsNullOrWhiteSpace(model.searchQuery)) { var search = model.searchQuery.ToLower(); source = source.Where(x => x.Title.ToLower().Contains(search) || x.Description.ToLower().Contains(search) || x.InvoiceNumber.ToString().Contains(search) || x.PosoNumber.ToString().Contains(search) || x.Tax.ToString().Contains(search) || x.CurrencyCode.ToString().Contains(search) || x.CurrencySymbol.ToString().Contains(search) || x.FirstName.ToString().Contains(search) || x.LastName.ToString().Contains(search) || x.BussinessName.ToString().Contains(search) || x.Phone.ToString().Contains(search) || x.Mobile.ToString().Contains(search) || x.PersonalEmail.ToString().Contains(search) || x.BussinessEmail.ToString().Contains(search) || x.Gstin.ToString().Contains(search) || x.AccountNumber.ToString().Contains(search) || x.Address1.ToString().Contains(search) ); } // Get's No of Rows Count int count = source.Count(); // Parameter is passed from Query string if it is null then it default Value will be pageNumber:1 int CurrentPage = model.pageNumber; // Parameter is passed from Query string if it is null then it default Value will be pageSize:20 int PageSize = model.pageSize; // Display TotalCount to Records to User int TotalCount = count; // Calculating Totalpage by Dividing (No of Records / Pagesize) int TotalPages = (int)Math.Ceiling(count / (double)PageSize); // Returns List of Customer after applying Paging var items = source.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList(); // if CurrentPage is greater than 1 means it has previousPage var previousPage = CurrentPage > 1 ? "Yes" : "No"; // if TotalPages is greater than CurrentPage means it has nextPage var nextPage = CurrentPage < TotalPages ? "Yes" : "No"; // Returing List of Customers Collections ResponseModel <InvoiceListViewModel> obj = new ResponseModel <InvoiceListViewModel>(); obj.totalCount = TotalCount; obj.pageSize = PageSize; obj.currentPage = CurrentPage; obj.totalPages = TotalPages; obj.previousPage = previousPage; obj.nextPage = nextPage; obj.searchQuery = string.IsNullOrEmpty(model.searchQuery) ? "no parameter passed" : model.searchQuery; obj.dataList = items.ToList(); return(obj); } return(null); }