/// <summary> /// Shippers テーブルのレコード数をカウントする /// </summary> /// <param name="ddlDap">データプロバイダ</param> /// <param name="ddlMode1">静的、動的のクエリ モード(共通Dao選択時)</param> /// <param name="ddlMode2">静的、動的のクエリ モード</param> /// <param name="ddlExRollback">コミット、ロールバック</param> /// <returns>Shippers テーブルのレコード数を表示するためのPartialViewResult</returns> public ActionResult GetCount(string ddlDap, string ddlMode1, string ddlMode2, string ddlExRollback) { // 引数クラスを生成 // 下位(B・D層)は、テスト クラスを流用する TestParameterValue testParameterValue = new TestParameterValue( "CrudMu", "button1", "SelectCount", ddlDap + "%" + ddlMode1 + "%" + ddlMode2 + "%" + ddlExRollback, new MyUserInfo("aaa", "192.168.1.1")); // 戻り値 TestReturnValue testReturnValue; // 分離レベルの設定 DbEnum.IsolationLevelEnum iso = DbEnum.IsolationLevelEnum.DefaultTransaction; // B層呼出し+都度コミット LayerB layerB = new LayerB(); testReturnValue = (TestReturnValue)layerB.DoBusinessLogic(testParameterValue, iso); // 結果表示するメッセージ string message = ""; CrudModel model = new CrudModel(); if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) message = "ErrorMessageID:" + testReturnValue.ErrorMessageID + ";"; message += "ErrorMessage:" + testReturnValue.ErrorMessage + ";"; message += "ErrorInfo:" + testReturnValue.ErrorInfo; } else { // 結果(正常系) message = testReturnValue.Obj.ToString() + "件のデータがあります"; } // メッセージを設定。 model.Message = message; // Ajax.BeginFormでは、以下のように記述することで部分更新が可能。 return(PartialView("_MessageView", model)); }
public void FormHelper_FieldsValidationInsert_WithNoImage() { //Arrange CrudModel model = new CrudModel { ID = null, Name = "Some name", Image = null, Description = "Some description" }; string noName = "You need to load an image!\n"; //Act var result = helper.FieldsValidationInsert(model); //Assert Assert.False(result); Assert.Equal(noName, helper.sbErrorMessage.ToString()); }
public void FormHelper_FieldsValidationInsert_Pass() { //Arrange CrudModel model = new CrudModel { ID = null, Name = "Some name", Image = new byte[0], Description = "Some description" }; string noName = ""; //Act var result = helper.FieldsValidationInsert(model); //Assert Assert.True(result); Assert.Equal(noName, helper.sbErrorMessage.ToString()); }
public void FormHelper_FieldsValidationInsert_WithID() { //Arrange CrudModel model = new CrudModel { ID = 1, Name = "Randon Name", Image = new byte[0], Description = "Some description" }; string withID = "Please Click on Clear Fields first\nThen load an image\nand fill the name field."; //Act var result = helper.FieldsValidationInsert(model); //Assert Assert.False(result); Assert.Equal(withID, helper.sbErrorMessage.ToString()); }
public void FormHelper_FieldsValidationUpdate_Fail() { //Arragen string noID = "Please Click on Clear Fields first\nThen choose a record from the Grid\nOr use the search button to find a record.\n"; var model = new CrudModel { ID = null, Description = "aaa", Name = "xxx", Image = new byte[0] }; //Act var result = helper.FieldsValidationUpdate(model); //Assert Assert.False(result); Assert.Contains(noID, helper.sbErrorMessage.ToString()); }
public void FormHelper_FieldsValidationInsert_WithNoName() { //Arrange CrudModel model = new CrudModel { ID = null, Name = string.Empty, Image = new byte[0], Description = "Some description" }; string noName = "Name should have value!\n"; //Act var result = helper.FieldsValidationInsert(model); //Assert Assert.False(result); Assert.Equal(noName, helper.sbErrorMessage.ToString()); }
private void btn_delete_Click(object sender, EventArgs e) { if (_formHelper.FieldsValidationDelete(textBox_ID.Text)) { CrudModel crudModel = new CrudModel { ID = int.Parse(textBox_ID.Text) }; int result = _database.DeleteModel(crudModel); ResultOperation(result, DELETE_SUCCESS); } else { MessageBox.Show( _formHelper.sbErrorMessage.ToString(), "Validation Fields", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); } _formHelper.sbErrorMessage.Clear(); _log.Info(new LogDetails().SetLogClass(this.GetType().Name).SetLogMethod(LogDetails.GetCurrentMethod())); }
public ActionResult Index() { try { StringContent content = new StringContent(JsonConvert.SerializeObject(new CrudRequest()), Encoding.UTF8, "application/json"); HttpResponseMessage httpResponse = _client.PostAsync("api/Crud/GetRecords", content).Result; string data = httpResponse.Content.ReadAsStringAsync().Result; CrudResponse response = JsonConvert.DeserializeObject <CrudResponse>(data); CrudModel model = new CrudModel(response.Cruds); return(View(model)); } catch (CrudException ex) { } catch (Exception ex) { } return(View()); }
public async Task <IActionResult> UpdateData(CrudModel model) { if (ModelState.IsValid) { var success = await new RestfulClient(_logger, HttpContext.Session.Get <AuthenticationResponse>("AuthenticationResponse")?.Token).UpdateLookUpData(model); if (success) { TempData["MessageType"] = MessageTypes.Success; TempData["Message"] = Messages.successfullyUpdated; ViewBag.MessageType = MessageTypes.Success; ViewBag.Message = Messages.successfullyUpdated; } else { ViewBag.MessageType = MessageTypes.Error; ViewBag.Message = Messages.GeneralError; } } return(RedirectToAction(model.ActionName)); }
public async Task CanCreate() { var database = new Mock <IDatabase <CrudId, CrudModel> >(); database.Setup(d => d.Create(It.IsAny <CrudModel>())) .Returns(Task.FromResult(new CrudId("new-model-id"))); using var server = CreateTestCrudServer(database.Object); var model = new CrudModel("", "model-body"); var requestContent = new StringContent(JsonConvert.SerializeObject(model)); var client = server.CreateClient(); // Act var response = await client.PostAsync("/model", requestContent); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); var content = await response.Content.ReadAsStringAsync(); Assert.Equal("new-model-id", content); }
public async Task <IHttpActionResult> InsertMultipleChilds(int id, List <Dictionary <string, object> > Items) { var meta = await db.META_BO.FindAsync(id); if (meta == null) { return(NotFound()); } /* ACCESS RIGHTS */ try { UserRoleManager.Instance.VerifyWrite(meta.BO_DB_NAME); } catch (UnauthorizedAccessException ex) { return(Content(HttpStatusCode.Forbidden, ex.Message)); } /* FIN ACCESS RIGHTS */ List <object> result = new List <object>(); string insert = "-"; bool deleted = false; foreach (var ligne in Items) { BO bo_model = new BO() { CREATED_BY = User.Identity.Name, CREATED_DATE = DateTime.Now, UPDATED_BY = User.Identity.Name, UPDATED_DATE = DateTime.Now, STATUS = "1", BO_TYPE = id.ToString(), VERSION = meta.VERSION }; db.BO.Add(bo_model); await db.SaveChangesAsync(); db.BO_CHILDS.Add(new BO_CHILDS() { BO_PARENT_ID = (long)ligne["parentId"], BO_CHILD_ID = bo_model.BO_ID, RELATION = "1..*" }); await db.SaveChangesAsync(); int id_ = (int)bo_model.BO_ID; ligne.Remove("parentId"); var model = new CrudModel() { MetaBoID = id, Items = ligne, MetaBO = meta }; model.Items.Add("BO_ID", id_); insert = model.Insert(); result.Add(new { inserted = insert, BO_ID = id_ }); if (insert != "") { deleted = true; db.Entry(bo_model).State = EntityState.Deleted; } } if (deleted) { await db.SaveChangesAsync(); } return(Ok(result)); }
public ActionResult Index() { CrudModel model = new CrudModel(); return(View(model)); }
/// <summary> /// Shippers テーブルのレコード全件を、動的 SQL を使用して取得する /// </summary> /// <param name="ddlDap">データプロバイダ</param> /// <param name="ddlMode1">静的、動的のクエリ モード(共通Dao選択時)</param> /// <param name="ddlMode2">静的、動的のクエリ モード</param> /// <param name="ddlExRollback">コミット、ロールバック</param> /// <param name="ddlOrderColumn">並び替え対象列</param> /// <param name="ddlOrderSequence">昇順・降順</param> /// <returns>Shippers テーブルのレコードを表示するPartialViewResult</returns> public ActionResult SelectAll_DSQL(string ddlDap, string ddlMode1, string ddlMode2, string ddlExRollback, string ddlOrderColumn, string ddlOrderSequence) { // 引数クラスを生成 // 下位(B・D層)は、テスト クラスを流用する TestParameterValue testParameterValue = new TestParameterValue( "CrudMu", "button5", "SelectAll_DSQL", ddlDap + "%" + ddlMode1 + "%" + ddlMode2 + "%" + ddlExRollback, new MyUserInfo("aaa", "192.168.1.1")); // 動的SQLの要素を設定 testParameterValue.OrderColumn = ddlOrderColumn; testParameterValue.OrderSequence = ddlOrderSequence; // 戻り値 TestReturnValue testReturnValue; // 分離レベルの設定 DbEnum.IsolationLevelEnum iso = DbEnum.IsolationLevelEnum.DefaultTransaction; // B層呼出し+都度コミット LayerB layerB = new LayerB(); testReturnValue = (TestReturnValue)layerB.DoBusinessLogic(testParameterValue, iso); // 結果表示するメッセージ string message = ""; if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) message = "ErrorMessageID:" + testReturnValue.ErrorMessageID + ";"; message += "ErrorMessage:" + testReturnValue.ErrorMessage + ";"; message += "ErrorInfo:" + testReturnValue.ErrorInfo; // Ajax.BeginFormでは、UpdateTargetIdで指定した // ターゲット以外を更新する場合、JavaScriptでの対応が必要。 // #ここではjQueryを使用している。 string scriptText = "$('#lblMessage').text('" + message + "');"; return(JavaScript(scriptText)); } else { // 結果(正常系) CrudModel model = new CrudModel(); model.shippers = new DataSets.DsNorthwind.ShippersDataTable(); DataTable dt = (DataTable)testReturnValue.Obj; foreach (DataRow row in dt.Rows) { DataSets.DsNorthwind.ShippersRow srow = model.shippers.NewShippersRow(); srow.ShipperID = int.Parse(row[0].ToString()); srow.CompanyName = row[1].ToString(); srow.Phone = row[2].ToString(); model.shippers.Rows.Add(srow); } // Ajax.BeginFormでは、以下のように記述することで部分更新が可能。 return(PartialView("_ChartView", model)); } }
public IActionResult Index(CrudModel model) { return(View(model)); }
public ActionResult Edit(CrudModel model) { new CrudModel().Actualizar(model); return(RedirectToAction("/Index")); }
// GET: Peliculas/Create public ActionResult Edit(int id) { var data = new CrudModel().Consulta(id); return(View(data)); }
public ActionResult Create(CrudModel model) { new CrudModel().Insertar(model); return(RedirectToAction("/Index")); }
public ActionResult Index() { var data = new CrudModel().Consulta(); return(View(data)); }
public UpdateCrudModelRequest(string id, CrudModel model) => (Id, Model) = (new CrudId(id), model);
public async Task <IHttpActionResult> Insert(int id, Dictionary <string, object> Items) { Logger.Info("POST Crud: " + id); var model = new CrudModel() { MetaBoID = id, Items = Items }; // var meta = await db.META_BO.FindAsync(model.MetaBoID); var meta = db.META_BO.Find(model.MetaBoID); /* ACCESS RIGHTS */ try { UserRoleManager.Instance.VerifyWrite(meta.BO_DB_NAME); } catch (UnauthorizedAccessException ex) { return(Content(HttpStatusCode.Forbidden, ex.Message)); } /* FIN ACCESS RIGHTS */ BO bo_model = new BO() { CREATED_BY = User.Identity.Name, CREATED_DATE = DateTime.Now, UPDATED_BY = User.Identity.Name, UPDATED_DATE = DateTime.Now, STATUS = "1", BO_TYPE = model.MetaBoID.ToString(), VERSION = meta.VERSION }; db.BO.Add(bo_model); await db.SaveChangesAsync(); int id_ = (int)bo_model.BO_ID; BO_Insert_return = id_; model.MetaBO = meta; model.BO_ID = id_; model.Items.Add("BO_ID", model.BO_ID); //return Ok(model.FormatInsert()); string insert = model.Insert(); // Workflow executer begin var s = new SGBD(); var db_workflow = s.Cmd(" select * from WORKFLOW CROSS APPLY OPENJSON(ITEMS) with(type varchar(50) '$.type', " + " precedent varchar(50) '$.precedent', [index] int '$.index', val nvarchar(500) '$.value.value') as jsonValues where ACTIVE = 1 and jsonValues.val = " + id + "and jsonValues.type = 'bo'"); dynamic _JSON; var where = ""; foreach (DataRow item in db_workflow.Rows) { _JSON = System.Web.Helpers.Json.Decode(item["ITEMS"].ToString()); int level = 0; for (var i = (int)item["index"] + 1; i < _JSON.Length; i++) { var elm = _JSON[i]; if (elm["status"] != "deleted") { where = ""; level++; if (elm["type"] == "validation") { foreach (var rule in elm.value.rules) { var value = rule["value"]; if (!"int,float,decimal,nvarchar(MAX)".Contains(rule["field"]["DB_TYPE"])) { value = "'" + value + "'"; } where += " " + rule["logic"] + " " + rule["field"]["DB_NAME"] + " " + rule["condition"] + " " + value; } var check_validation = s.Cmd("select * from " + meta.BO_DB_NAME + " where BO_ID=" + model.BO_ID + " " + where); if (check_validation.Rows.Count > 0) { TASK valid = new TASK() { BO_ID = id_, JSON_DATA = System.Web.Helpers.Json.Encode(elm.value.validators), CREATED_BY = User.Identity.Name, CREATED_DATE = DateTime.Now, STATUS = elm.value.status, ETAT = 0, TASK_LEVEL = level, TASK_TYPE = "VALIDATION" }; db.TASK.Add(valid); foreach (var _validator in elm.value.validators) { NOTIF notification = new NOTIF() { VALIDATOR = _validator["email"], CREATED_DATE = DateTime.Now, ETAT = 0 }; db.NOTIF.Add(notification); } db.SaveChanges(); } } else if (elm["type"] == "bo") { TASK valid = new TASK() { BO_ID = id_, JSON_DATA = System.Web.Helpers.Json.Encode(elm.value), CREATED_BY = User.Identity.Name, CREATED_DATE = DateTime.Now, ETAT = 0, TASK_LEVEL = level, TASK_TYPE = "BO" }; db.TASK.Add(valid); db.SaveChanges(); var task_id = (int)valid.TASK_ID; // await Insert_Bo_Using_Mapping(id, meta.BO_DB_NAME, model.BO_ID, task_id); } } } } if (insert == "") { BO_Insert_return = id_; return(Ok(model)); } else { return(InternalServerError(new Exception(insert))); } }
/// <summary> /// Shippers テーブルのレコード全件を、動的 SQL を使用して取得する /// </summary> /// <param name="ddlDap">データプロバイダ</param> /// <param name="ddlMode1">静的、動的のクエリ モード(共通Dao選択時)</param> /// <param name="ddlMode2">静的、動的のクエリ モード</param> /// <param name="ddlExRollback">コミット、ロールバック</param> /// <param name="ddlOrderColumn">並び替え対象列</param> /// <param name="ddlOrderSequence">昇順・降順</param> /// <param name="form">入力フォームの情報</param> /// <returns>再描画(ViewResult)</returns> public ActionResult SelectAll_DSQL(string ddlDap, string ddlMode1, string ddlMode2, string ddlExRollback, string ddlOrderColumn, string ddlOrderSequence, FormCollection form) { // 引数クラスを生成 // 下位(B・D層)は、テスト クラスを流用する TestParameterValue testParameterValue = new TestParameterValue( "CrudMu", "button5", "SelectAll_DSQL", ddlDap + "%" + ddlMode1 + "%" + ddlMode2 + "%" + ddlExRollback, new MyUserInfo("aaa", "192.168.1.1")); // 動的SQLの要素を設定 testParameterValue.OrderColumn = ddlOrderColumn; testParameterValue.OrderSequence = ddlOrderSequence; // 戻り値 TestReturnValue testReturnValue; // 分離レベルの設定 DbEnum.IsolationLevelEnum iso = DbEnum.IsolationLevelEnum.DefaultTransaction; // B層呼出し+都度コミット LayerB layerB = new LayerB(); testReturnValue = (TestReturnValue)layerB.DoBusinessLogic(testParameterValue, iso); // 結果表示するメッセージ string message = ""; CrudModel model = new CrudModel(); // 値の復元のため、CopyInputValuesを呼び出す。 model.CopyInputValues(form); if (testReturnValue.ErrorFlag == true) { // 結果(業務続行可能なエラー) message = "ErrorMessageID:" + testReturnValue.ErrorMessageID + ";"; message += "ErrorMessage:" + testReturnValue.ErrorMessage + ";"; message += "ErrorInfo:" + testReturnValue.ErrorInfo; // メッセージを設定。 model.Message = message; } else { // 結果(正常系) model.shippers = new DataSets.DsNorthwind.ShippersDataTable(); DataTable dt = (DataTable)testReturnValue.Obj; foreach (DataRow row in dt.Rows) { DataSets.DsNorthwind.ShippersRow srow = model.shippers.NewShippersRow(); srow.ShipperID = int.Parse(row[0].ToString()); srow.CompanyName = row[1].ToString(); srow.Phone = row[2].ToString(); model.shippers.Rows.Add(srow); } } // Html.BeginFormでは、全体更新。 return(View("Index", model)); }