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(); } }
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(); } }