public override async Task ComposeModelAsync(Doc doc, IUpdateModel updater) { var model = new CategoryInputViewModel { SelectedCategories = GetCategoriesToAdd() }; await updater.TryUpdateModelAsync(model); if (updater.ModelState.IsValid) { var categoriesToAdd = GetCategoriesToAdd(); if (categoriesToAdd?.Count > 0) { foreach (var categoryId in categoriesToAdd) { if (categoryId > 0) { doc.CategoryId = categoryId; } } } else { doc.CategoryId = 0; } } }
/// <summary> /// 新規登録情報取得. /// </summary> /// <returns></returns> public CategoryInputViewModel GetInputNewData() { CategoryInputViewModel retModel = new CategoryInputViewModel(); // 返却モデルの固定値部分をセット. retModel.system_user_name = string.Empty; retModel.delete_state = "0"; return(retModel); }
public override async Task ComposeModelAsync(Moderator moderator, IUpdateModel updater) { var model = new CategoryInputViewModel { SelectedCategories = GetChannelsToAdd() }; await updater.TryUpdateModelAsync(model); if (updater.ModelState.IsValid) { moderator.CategoryId = model.SelectedCategories.FirstOrDefault(); } }
public IActionResult AddCategory(CategoryInputViewModel model) { if (ModelState.IsValid) { Category c = new Category { Name = model.Name }; _reposCategory.AddCategory(c); return(RedirectToAction("CategoryList")); } return(View()); }
public async Task <IViewComponentResult> InvokeAsync(CategoryInputOptions options) { if (options.SelectedCategories == null) { options.SelectedCategories = new int[0]; } var categories = await BuildChannelSelectionsAsync(options); var model = new CategoryInputViewModel(categories) { HtmlName = options.HtmlName }; return(View(model)); }
/// <summary> /// 編集結果登録. /// </summary> /// <returns></returns> public bool RegistrationInputEditData(CategoryInputViewModel reqModel) { bool retVal = false; // 指定IDの情報を取得. var updModel = db.m_system_users.Find(reqModel.system_user_id); // DB登録に必要な情報を成形する. // 固有項目. updModel.role_id = reqModel.role_id; updModel.system_user_name = reqModel.system_user_name; updModel.mail_address = reqModel.mail_address; updModel.password = reqModel.password; // 必須項目. updModel.update_function = "aaaaaa"; updModel.update_date_time = DateTime.Now; updModel.update_system_user = "******"; //db.m_system_users.Attach(updModel.First()); db.Entry(updModel).State = EntityState.Modified; try { // DB登録. db.SaveChanges(); // DB登録に成功したので、返却値を更新. retVal = true; } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var error in errors.ValidationErrors) { Trace.WriteLine(error.ErrorMessage); // VisualStudioの出力に表示. } } } return(retVal); }
/// <summary> /// 新規登録. /// </summary> /// <returns></returns> public bool RegistrationInputNewData(CategoryInputViewModel reqModel) { bool retVal = false; // DB登録に必要な情報を成形する. m_system_users newModel = new m_system_users(); // 固有項目. newModel.role_id = reqModel.role_id; newModel.system_user_name = reqModel.system_user_name; newModel.mail_address = reqModel.mail_address; newModel.password = reqModel.password; // 削除状態. newModel.delete_state = reqModel.delete_state; // 必須項目. newModel.create_function = "aaaaaa"; newModel.create_date_time = DateTime.Now; newModel.create_user = "******"; db.m_system_users.Add(newModel); try { // DB登録. db.SaveChanges(); // DB登録に成功したので、返却値を更新. retVal = true; } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { foreach (var errors in ex.EntityValidationErrors) { foreach (var error in errors.ValidationErrors) { Trace.WriteLine(error.ErrorMessage); // VisualStudioの出力に表示. } } } return(retVal); }
public override async Task ComposeModelAsync(Topic topic, IUpdateModel updater) { var model = new CategoryInputViewModel { SelectedCategories = GetCategoriesToAdd() }; await updater.TryUpdateModelAsync(model); if (updater.ModelState.IsValid) { var categoriesToAdd = GetCategoriesToAdd(); if (categoriesToAdd != null) { foreach (var categoryId in categoriesToAdd) { if (categoryId > 0) { topic.CategoryId = categoryId; } } } } }
public async Task <IActionResult> Add(CategoryInputViewModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } if (this.categoriesService.ExistCategoryByName(inputModel.Name)) { this.ModelState.AddModelError(string.Empty, CategoryExist); return(this.View()); } try { await this.categoriesService.AddAsync(inputModel.Name); return(this.RedirectToAction("Index")); } catch (System.Exception) { return(this.BadRequest()); } }