public void Persist <T>(_Entity entity) { if (typeof(T) == typeof(User)) { UserController.Create((User)entity); } else if (typeof(T) == typeof(AppLocale)) { AppLocaleController.Create((AppLocale)entity); } else if (typeof(T) == typeof(AppText)) { AppTextController.Create((AppText)entity); } else if (typeof(T) == typeof(Bank)) { BankController.Create((Bank)entity); } else if (typeof(T) == typeof(Battle)) { BattleController.Create((Battle)entity); } else if (typeof(T) == typeof(City)) { CityController.Create((City)entity); } else if (typeof(T) == typeof(Harbor)) { HarborController.Create((Harbor)entity); } else if (typeof(T) == typeof(Inventory)) { InventoryController.Create((Inventory)entity); } else if (typeof(T) == typeof(Item)) { ItemController.Create((Item)entity); } else if (typeof(T) == typeof(Market)) { MarketController.Create((Market)entity); } else if (typeof(T) == typeof(Powerup)) { PowerupController.Create((Powerup)entity); } else if (typeof(T) == typeof(ProfileAI)) { ProfileAiController.Create((ProfileAI)entity); } else if (typeof(T) == typeof(Quest)) { QuestController.Create((Quest)entity); } else if (typeof(T) == typeof(Resource)) { ResourceController.Create((Resource)entity); } else if (typeof(T) == typeof(Reward)) { RewardController.Create((Reward)entity); } else if (typeof(T) == typeof(Scenario)) { ScenarioController.Create((Scenario)entity); } else if (typeof(T) == typeof(UserGame)) { UserGameController.Create((UserGame)entity); } else if (typeof(T) == typeof(Vessel)) { VesselController.Create((Vessel)entity); } else if (typeof(T) == typeof(Weapon)) { WeaponController.Create((Weapon)entity); } else { throw new Exception("Controller not implemented yet."); } }
/// <summary> /// /// </summary> /// <param name="e"></param> private void Create(DirectEventArgs e) { try { var path = string.Empty; if (fufTepTinHangLoat.HasFile) { path = UploadFile(fufTepTinHangLoat, hdfTypePage.Text.Equals("KhenThuong") ? Constant.PathReward : Constant.PathDiscipline); } foreach (var itemRow in chkEmployeeRowSelection.SelectedRows) { if (hdfTypePage.Text.Equals("KhenThuong")) { string reasonReward; if (hdfIsDanhMuc2.Text == @"0") { var reason = new cat_ReasonReward { Name = cbbLyDoHangLoat.Text }; cat_ReasonRewardServices.Create(reason); reasonReward = cbbLyDoHangLoat.Text; } else { reasonReward = cbbLyDoHangLoat.SelectedItem.Text; } if (string.IsNullOrEmpty(reasonReward)) { Dialog.Alert("Thông báo", "Không tìm thấy lý do khen thưởng. Vui lòng thử lại!"); return; } if (txtSoQuyetDinhHangLoat.Text == "") { GenerateRewardDecisionNumber(); } var record = new RewardModel { RecordId = Convert.ToInt32(itemRow.RecordID), DecisionNumber = txtSoQuyetDinhHangLoat.Text.Trim(), DecisionMaker = tgfNguoiQuyetDinhHangLoat.Text.Trim(), FormRewardId = int.Parse(hdfHinhThucHangLoat.Text), LevelRewardId = int.Parse(hdfLevelManyId.Text), Reason = reasonReward, SourceDepartment = txtSourceDepartment.Text, Note = txtGhuChuHangLoat.Text.Trim() }; var makerPosition = hdfIsMakerPosition.Text == @"0" ? cbxMakerPosition.Text : cbxMakerPosition.SelectedItem.Text; record.MakerPosition = makerPosition; if (!string.IsNullOrEmpty(txtMoneyAmount.Text)) { record.MoneyAmount = decimal.Parse("0" + txtMoneyAmount.Text); } record.CreatedDate = DateTime.Now; record.CreatedBy = CurrentUser.User.UserName; record.EditedDate = DateTime.Now; record.EditedBy = CurrentUser.User.UserName; if (!DatetimeHelper.IsNull(dfNgayQuyetDinhHangLoat.SelectedDate)) { record.DecisionDate = dfNgayQuyetDinhHangLoat.SelectedDate; } if (!DatetimeHelper.IsNull(dfNgayHieuLuc.SelectedDate)) { record.EffectiveDate = dfNgayHieuLuc.SelectedDate; } record.AttachFileName = path != "" ? path : hdfTepDinhKemHangLoat.Text; RewardController.Create(record); } else { string reasonDiscipline; if (hdfIsDanhMuc2.Text == @"0") { var reason = new cat_ReasonDiscipline() { Name = cbbLyDoHangLoat.Text }; cat_ReasonDisciplineServices.Create(reason); reasonDiscipline = cbbLyDoHangLoat.Text; } else { reasonDiscipline = cbbLyDoHangLoat.SelectedItem.Text; } if (string.IsNullOrEmpty(reasonDiscipline)) { Dialog.Alert("Thông báo", "Không tìm thấy lý do khen thưởng. Vui lòng thử lại!"); return; } if (txtSoQuyetDinhHangLoat.Text == "") { GenerateRewardDecisionNumber(); } var record = new DisciplineModel { RecordId = Convert.ToInt32(itemRow.RecordID), DecisionNumber = txtSoQuyetDinhHangLoat.Text.Trim(), DecisionMaker = tgfNguoiQuyetDinhHangLoat.Text.Trim(), FormDisciplineId = int.Parse(hdfHinhThucHangLoat.Text), LevelDisciplineId = int.Parse(hdfLevelManyId.Text), Reason = reasonDiscipline, SourceDepartment = txtSourceDepartment.Text, Note = txtGhuChuHangLoat.Text.Trim() }; var makerPosition = hdfIsMakerPosition.Text == @"0" ? cbxMakerPosition.Text : cbxMakerPosition.SelectedItem.Text; record.MakerPosition = makerPosition; record.CreatedDate = DateTime.Now; record.CreatedBy = CurrentUser.User.UserName; record.EditedDate = DateTime.Now; record.EditedBy = CurrentUser.User.UserName; if (!DatetimeHelper.IsNull(dfNgayQuyetDinhHangLoat.SelectedDate)) { record.DecisionDate = dfNgayQuyetDinhHangLoat.SelectedDate; } if (!DatetimeHelper.IsNull(dfExpireDate.SelectedDate)) { record.ExpireDate = dfExpireDate.SelectedDate; } record.AttachFileName = path != "" ? path : hdfTepDinhKemHangLoat.Text; DisciplineController.Create(record); } } grp_KhenThuongKyLuat.Reload(); ResetForm(); wdKhenThuongKyLuatHangLoat.Hide(); } catch (Exception ex) { Dialog.Alert("Có lỗi xảy ra trong quá trình tạo quyết định: {0}".FormatWith(ex.Message)); } }