using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataAcess.ExpenseTrackerBudget;
using Domain.ExpenseTrackerBudget;
using Syncfusion.Mvc.Grid;
using Syncfusion.Mvc.Shared;
namespace ExpenseTrackerBudget.Controllers
{
public class GridController : Controller
{
private ExpenseContext _db = new ExpenseContext();
private GridEditing _gridEditProperties = new GridEditing();
/// <summary>
/// Used for rendering the grid initially.
/// </summary>
/// <returns>Veiw page, it displays the Grid</returns>
public ActionResult Index()
{
ViewData["data"] = _db.Expenses.ToList();
//ViewData["Mode"] = GridMode == null ? GridEditMode.ManualExcel : (GridEditMode)GridMode;
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(PagingParams args)
{
IEnumerable data = _db.Expenses.ToList();
if (args.RequestType == 0)
{
ViewData["data"] = data;
return View();
}
else
return data.GridJSONActions<Expense>();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult BulkSave([Bind(Prefix = "updatedRecords")]IEnumerable<Expense> orders, [Bind(Prefix = "addedRecords")]IEnumerable<Expense> addRcrds, [Bind(Prefix = "deletedRecords")]IEnumerable<Expense> delRcrds)
{
//Repository action method Update used for perform update the records into datasource
if (orders != null)
OrderRepository.Update(orders);
if (addRcrds != null)
OrderRepository.Add(addRcrds);
if (delRcrds != null)
{
OrderRepository.Delete(delRcrds);
}
//After save the records into datasource refresh the grid
var data = _db.Expenses.ToList();
return data.GridJSONActions<Expense>();
}}
public class OrderRepository
{
private static ExpenseContext _db = new ExpenseContext();
internal static void Delete(IEnumerable<Expense> delRcrds)
{
foreach (var expense in delRcrds)
{
_db.Expenses.Remove(expense);
_db.SaveChanges();
}
}
internal static void Update(IEnumerable<Expense> orders)
{
foreach (var expense in orders)
{
_db.Entry(expense).State = EntityState.Modified;
_db.SaveChanges();
}
}
internal static void Add(IEnumerable<Expense> addRcrds)
{
foreach (var expense in addRcrds)
{
expense.Id = Guid.NewGuid();
// if (expense.IsValid)
//{
_db.Expenses.Add(expense);
_db.SaveChanges();
//}
}
}
}
}
The grid renders fine but when I click the Add button to add a new row the cells shift over and I'm only able to edit one column.... Please let me know if you have any questions or concerns..