public ActionResult Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <Deca_Company> items) { if (asset.Create) { if (items != null && ModelState.IsValid) { using (var dbConn = Helpers.OrmliteConnection.openConn()) { foreach (var item in items) { using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted)) { try { item.IsNew = true; item.CreatedAt = DateTime.Now; item.CreatedBy = User.Identity.Name; dbConn.Insert(item); int Id = (int)dbConn.GetLastInsertId(); item.Id = Id; item.CompanyID = "C" + DateTime.Now.ToString("yyMMdd") + Id; //item.CompanyID = "C" + DateTime.Now.ToString("yyMMdd") + string.Format("{0:000}", Id); dbConn.Update(item); var log = new Deca_Company_Log(); log.CompanyID = item.CompanyID; log.Log = item; log.CreatedAt = DateTime.Now; log.CreatedBy = currentUser.UserName; dbConn.Insert(log); dbTrans.Commit(); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(Json(items.ToDataSourceResult(request, ModelState))); } } } } } } else { ModelState.AddModelError("", "Don't have permission"); } return(Json(items.ToDataSourceResult(request, ModelState))); }
public ActionResult Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <Deca_Company> items) { if (asset.Update) { if (items != null && ModelState.IsValid) { using (var dbConn = Helpers.OrmliteConnection.openConn()) { foreach (var item in items) { using (var dbTrans = dbConn.OpenTransaction(IsolationLevel.ReadCommitted)) { item.IsNew = true; item.UpdatedAt = DateTime.Now; item.UpdatedBy = User.Identity.Name; dbConn.Update(item); var log = new Deca_Company_Log(); log.CompanyID = item.CompanyID; log.Log = item; log.CreatedAt = DateTime.Now; log.CreatedBy = currentUser.UserName; dbConn.Insert(log); dbTrans.Commit(); } } } } } else { ModelState.AddModelError("", "Don't have permission"); } return(Json(items.ToDataSourceResult(request, ModelState))); }