public JsonResult GetCustomers(string sidx, string sort, int page, int rows) { MCustomerContext context = new MCustomerContext(); sort = (sort == null) ? "" : sort; int pageIndex = Convert.ToInt32(page) - 1; int pageSize = rows; //var StudentList = context.MCustomers.Select( // t => new // { // t.CustomerId, // t.CustomerName // }); var customer = context.MCustomers.ToList(); var order = context.MOrders.ToList(); var product = context.MProducts.ToList(); var viewModel = new CustomerViewModel { customers = new MCustomer(), orders = order, products = product }; var innerJoinQuery = from category in categories join prod in products on category.ID equals prod.CategoryID select new { ProductName = prod.Name, Category = category.Name }; //produces flat sequence int totalRecords = StudentList.Count(); var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows); if (sort.ToUpper() == "DESC") { StudentList = StudentList.OrderByDescending(t => t.CustomerName); StudentList = StudentList.Skip(pageIndex * pageSize).Take(pageSize); } else { StudentList = StudentList.OrderBy(t => t.CustomerName); StudentList = StudentList.Skip(pageIndex * pageSize).Take(pageSize); } var jsonData = new { total = totalPages, page, records = totalRecords, rows = StudentList }; return(Json(jsonData, JsonRequestBehavior.AllowGet)); }
public string Edit(CustomerViewModel Model) { MCustomerContext context = new MCustomerContext(); string msg; try { if (ModelState.IsValid) { context.Entry(Model).State = EntityState.Modified; context.SaveChanges(); msg = "Saved Successfully"; } else { msg = "Validation data not successfully"; } } catch (Exception ex) { msg = "Error occured:" + ex.Message; } return(msg); }
public JsonResult GetCustomers(string sidx, string sort, int page, int rows) { MCustomerContext context = new MCustomerContext(); sort = (sort == null) ? "" : sort; int pageIndex = Convert.ToInt32(page) - 1; int pageSize = rows; //List import---> var customer = context.MCustomers.ToList(); var order = context.MOrders.ToList(); var product = context.MProducts.ToList(); //List import---> #region <==Two Table Join==> var innerJoinQuery = customer.Join(order, c => c.CustomerId, m => m.CustomerId, (c, m) => new { c.CustomerName, m.CustomerId, m.OrderId }); #endregion #region <==Thord Table Join==> //var threeTable = innerJoinQuery.Join(product, // c => c.OrderId, // m => m.OrderId, // (c, m) => new { // c.CustomerId, // c.CustomerName, // c.OrderId, // m.ProductId, // m.ProductName // }); #endregion int totalRecords = innerJoinQuery.Count(); var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows); if (sort.ToUpper() == "DESC") { innerJoinQuery = innerJoinQuery.OrderByDescending(t => t.CustomerId); innerJoinQuery = innerJoinQuery.Skip(pageIndex * pageSize).Take(pageSize); } else { innerJoinQuery = innerJoinQuery.OrderBy(t => t.CustomerId); innerJoinQuery = innerJoinQuery.Skip(pageIndex * pageSize).Take(pageSize); } var jsonData = new { total = totalPages, page, records = totalRecords, rows = innerJoinQuery }; return(Json(jsonData, JsonRequestBehavior.AllowGet)); }