本文整理汇总了C#中SES.Service.OrmliteConnection.GetLastInsertId方法的典型用法代码示例。如果您正苦于以下问题:C# OrmliteConnection.GetLastInsertId方法的具体用法?C# OrmliteConnection.GetLastInsertId怎么用?C# OrmliteConnection.GetLastInsertId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SES.Service.OrmliteConnection
的用法示例。
在下文中一共展示了OrmliteConnection.GetLastInsertId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create(FormCollection form)
{
IDbConnection db = new OrmliteConnection().openConn();
try
{
if (!string.IsNullOrEmpty(form["RoleName"]))
{
var item = new Auth_Role();
item.RoleName = form["RoleName"];
item.IsActive = form["IsActive"] != null ? Convert.ToBoolean(form["IsActive"]) : false;
item.Note = !string.IsNullOrEmpty(form["Note"]) ? form["Note"] : "";
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] &&
string.IsNullOrEmpty(form["RoleID"])) // Tạo mới
{
item.RowCreatedAt = DateTime.Now;
item.RowCreatedBy = currentUser.UserID;
db.Insert<Auth_Role>(item);
long lastID = db.GetLastInsertId();
if (lastID > 0)
{
// Thêm Role vào Auth_Action
db.ExecuteSql("EXEC p_Auth_Role_GenerateAction_By_RoleID " + lastID + "," + currentUser.UserID);
}
return Json(new { success = true, insert = true, RoleID = lastID, createdat = item.RowCreatedAt, createdby = item.RowCreatedBy });
}
else if (userAsset.ContainsKey("Insert") && userAsset["Insert"] &&
Convert.ToInt32(form["RoleID"]) > 0 &&
Convert.ToInt32(form["IsCopy"]) == 1) // Sao chép
{
item.RoleID = Convert.ToInt32(form["RoleID"]);
item.RowCreatedAt = DateTime.Now;
item.RowCreatedBy = currentUser.UserID;
db.Insert<Auth_Role>(item);
long lastID = db.GetLastInsertId();
if (lastID > 0)
{
// Sao chép Action RoleID đã chọn vào RoleID vừa tạo
db.ExecuteSql("p_Auth_Role_CopyAction_By_RoleID " + item.RoleID + "," + lastID + "," + currentUser.UserID);
}
return Json(new { success = true, insert = true, RoleID = lastID, createdat = item.RowCreatedAt, createdby = item.RowCreatedBy });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] &&
Convert.ToInt32(form["RoleID"]) > 0) // Cập nhật
{
item.RoleID = Convert.ToInt32(form["RoleID"]);
item.RowCreatedAt = DateTime.Parse(form["RowCreatedAt"]);
item.RowCreatedBy = form["RowCreatedBy"];
item.RowUpdatedAt = DateTime.Now;
item.RowUpdatedBy = currentUser.UserID;
if (item.RowCreatedBy != "system")
{
db.Update<Auth_Role>(item);
}
return Json(new { success = true, RoleID = item.RoleID });
}
else
return Json(new { success = false, message = "Bạn không có quyền" });
}
else
{
return Json(new { success = false, message = "Chưa nhập giá trị" });
}
}
catch (Exception e)
{
log.Error("HOAdminAuthRole - Create - " + e.Message);
return Json(new { success = false, message = e.Message });
}
finally { db.Close(); }
}
示例2: Create
public ActionResult Create(Master_Announcement item)
{
//if (form.AllKeys.Contains("TextContent"))
//{
// item.TextContent = form.Get("TextContent");
//}
//CHECK IS NULL VALUE
if (string.IsNullOrEmpty(item.TextContent))
{
item.TextContent = "";
}
if (string.IsNullOrEmpty(item.HTMLContent))
{
item.HTMLContent = "";
}
if (string.IsNullOrEmpty(item.Title))
{
item.Title = "";
}
IDbConnection dbConn = new OrmliteConnection().openConn();
try
{
var isExist = dbConn.GetByIdOrDefault<Master_Announcement>(item.AnnouncementID);
if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
{
if (isExist != null)
{
return Json(new { success = false, message = "Đối tượng này đã tồn tại." });
}
item.CreatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
dbConn.Insert<Master_Announcement>(item);
long lastInsertId = dbConn.GetLastInsertId();
dbConn.Close();
return Json(new { success = true, AnnouncementID = lastInsertId, createdat = item.CreatedAt, createdby = item.CreatedBy });
}
else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
{
item.UpdatedAt = DateTime.Now;
item.CreatedBy = currentUser.UserID;
dbConn.Update<Master_Announcement>(item);
dbConn.Close();
return Json(new { success = true });
}
else
return Json(new { success = false, message = "You don't have permission" });
}
catch (Exception ex)
{
log.Error("AD_Announcement - Create - " + ex.Message);
return Json(new { success = false, message = ex.Message });
}
finally
{
dbConn.Close();
}
}