public ActionResult Result(ResultViewModel viewModel, FormCollection formCollection) { _tResultRepository.DbContext.BeginTransaction(); TResult result = _tResultRepository.GetResultByDate(viewModel.ResultDate.Value); if (result != null) { _tResultRepository.Delete(result); } result = new TResult(); result.SetAssignedIdTo(Guid.NewGuid().ToString()); result.ResultDate = viewModel.ResultDate; result.CreatedDate = DateTime.Now; result.CreatedBy = User.Identity.Name; result.DataStatus = EnumDataStatus.New.ToString(); result.ResultDets.Clear(); _tResultRepository.Save(result); //get prize for D2 and D3 games char[] prizeD1 = viewModel.prizeD4_1.ToCharArray(); string prizeD2 = viewModel.prizeD4_1.Substring(2, 2); string prizeD3 = viewModel.prizeD4_1.Substring(1, 3); //save details string strprizeD1 = string.Empty, formatWing = string.Empty; for (int i = 0; i < prizeD1.Length; i++) { strprizeD1 = prizeD1[i].ToString(); //calculate D1 SaveResultDet(result, EnumGame.D1, i + 1, strprizeD1); //calculate wing switch (i) { case 0: formatWing = "{0}xxx"; break; case 1: formatWing = "x{0}xx"; break; case 2: formatWing = "xx{0}x"; break; case 3: formatWing = "xxx{0}"; break; } SaveResultDet(result, EnumGame.WING, i + 1, string.Format(formatWing, strprizeD1)); } //calculate prize for paket char[] indexPrizePaket = ("0123").ToCharArray(); IList <string> indexResultPaket = indexPrizePaket.AllPermutationsNotDistinct().Where(x => x.Length == 2).ToList(); char[] prizePaket; for (int i = 0; i < indexResultPaket.Count; i++) { prizePaket = indexResultPaket[i].ToCharArray(); SaveResultDet(result, EnumGame.PAKET, i + 1, string.Format("{0}/{1}", prizeD1[int.Parse(prizePaket[0].ToString())], prizeD1[int.Parse(prizePaket[1].ToString())])); } //calculate prize for MK char[] prizeMK; for (int i = 0; i < indexResultPaket.Count; i++) { prizeMK = indexResultPaket[i].ToCharArray(); SaveResultDet(result, EnumGame.MK, i + 1, string.Format("{0}/{1}", prizeD1[int.Parse(prizeMK[0].ToString())], prizeD1[int.Parse(prizeMK[1].ToString())])); } //calculate prize for DTB string prizeD = viewModel.prizeD4_1.Substring(0, 2); string prizeT = viewModel.prizeD4_1.Substring(1, 2); string prizeB = viewModel.prizeD4_1.Substring(2, 2); SaveResultDet(result, EnumGame.D, 1, prizeD); SaveResultDet(result, EnumGame.T, 1, prizeT); SaveResultDet(result, EnumGame.B, 1, prizeB); //calculate prize for BK besar dan kecil SaveResultDet(result, EnumGame.BK_B, 101, viewModel.prizeD4_1); SaveResultDet(result, EnumGame.BK_B, 201, viewModel.prizeD4_2); SaveResultDet(result, EnumGame.BK_B, 301, viewModel.prizeD4_3); SaveResultDet(result, EnumGame.BK_K, 101, viewModel.prizeD4_1); SaveResultDet(result, EnumGame.BK_K, 201, viewModel.prizeD4_2); SaveResultDet(result, EnumGame.BK_K, 301, viewModel.prizeD4_3); SaveResultDet(result, EnumGame.D2, 1, prizeD2); SaveResultDet(result, EnumGame.D3, 1, prizeD3); SaveResultDet(result, EnumGame.D4TH, 1, viewModel.prizeD4_1); SaveResultDet(result, EnumGame.D4, 101, viewModel.prizeD4_1); SaveResultDet(result, EnumGame.D4, 201, viewModel.prizeD4_2); SaveResultDet(result, EnumGame.D4, 301, viewModel.prizeD4_3); SaveResultDet(result, EnumGame.D4, 401, viewModel.prizeD4_4_1); SaveResultDet(result, EnumGame.D4, 402, viewModel.prizeD4_4_2); SaveResultDet(result, EnumGame.D4, 403, viewModel.prizeD4_4_3); SaveResultDet(result, EnumGame.D4, 404, viewModel.prizeD4_4_4); SaveResultDet(result, EnumGame.D4, 405, viewModel.prizeD4_4_5); SaveResultDet(result, EnumGame.D4, 406, viewModel.prizeD4_4_6); SaveResultDet(result, EnumGame.D4, 407, viewModel.prizeD4_4_7); SaveResultDet(result, EnumGame.D4, 408, viewModel.prizeD4_4_8); SaveResultDet(result, EnumGame.D4, 409, viewModel.prizeD4_4_9); SaveResultDet(result, EnumGame.D4, 410, viewModel.prizeD4_4_10); SaveResultDet(result, EnumGame.D4, 501, viewModel.prizeD4_5_1); SaveResultDet(result, EnumGame.D4, 502, viewModel.prizeD4_5_2); SaveResultDet(result, EnumGame.D4, 503, viewModel.prizeD4_5_3); SaveResultDet(result, EnumGame.D4, 504, viewModel.prizeD4_5_4); SaveResultDet(result, EnumGame.D4, 505, viewModel.prizeD4_5_5); SaveResultDet(result, EnumGame.D4, 506, viewModel.prizeD4_5_6); SaveResultDet(result, EnumGame.D4, 507, viewModel.prizeD4_5_7); SaveResultDet(result, EnumGame.D4, 508, viewModel.prizeD4_5_8); SaveResultDet(result, EnumGame.D4, 509, viewModel.prizeD4_5_9); SaveResultDet(result, EnumGame.D4, 510, viewModel.prizeD4_5_10); bool Success = true; string Message = string.Empty; try { _tResultRepository.DbContext.CommitTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success; Success = true; Message = "Nomor keluar berhasil disimpan."; } catch (Exception ex) { _tResultRepository.DbContext.RollbackTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed; Success = false; Message = ex.GetBaseException().Message; } var e = new { Success, Message }; return(Json(e, JsonRequestBehavior.AllowGet)); }