public ActionResult Create(int id) { Model_UserExamInPersonPlanCreate model = new Model_UserExamInPersonPlanCreate() { ExamID = id }; return(PartialView(model)); }
public ActionResult Create(Model_UserExamInPersonPlanCreate model) { if (ModelState.IsValid) { var _User = db.Tbl_User.Where(x => x.User_Guid == model.UserGuid && x.User_IsDelete == false).SingleOrDefault(); if (db.Tbl_UserExamInPersonPlan.Where(x => x.UEIPP_UserID == _User.User_ID && x.UEIPP_EIPPID == model.ExamID && x.UEIPP_IsDelete == false).FirstOrDefault() != null) { TempData["TosterState"] = "info"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "آزمون مورد نظر قبلا خریداری شده است"; return(RedirectToAction("Details", "ExamInPerson", new { area = "Dashboard", id = model.ExamID })); } ; var _ExamInPersonPlan = db.Tbl_ExamInPersonPlan.Where(x => x.EIPP_ID == model.ExamID).SingleOrDefault(); if (_ExamInPersonPlan != null) { bool smsResult = true; Tbl_Payment _Payment = Purchase(_User, _ExamInPersonPlan.EIPP_Cost, ProductType.ExamInPerson, out bool walletResult, ref smsResult); if (_Payment != null) { db.Tbl_Payment.Add(_Payment); Tbl_Wallet _Wallet = db.Tbl_Wallet.Where(x => x.Wallet_UserID == _Payment.Payment_UserID).SingleOrDefault(); _Wallet.Wallet_Credit = _Payment.Payment_RemaingWallet - _Payment.Payment_Cost; _Wallet.Wallet_ModifiedDate = DateTime.Now; db.Entry(_Wallet).State = EntityState.Modified; Tbl_UserExamInPersonPlan _UserExamInPersonPlan = new Tbl_UserExamInPersonPlan { UEIPP_Guid = Guid.NewGuid(), UEIPP_UserID = new Rep_User().Get_UserIDWithGUID(model.UserGuid), UEIPP_EIPPID = model.ExamID, UEIPP_SeatNumber = 0, Tbl_Payment = _Payment, UEIPP_IsActive = true, UEIPP_CreationDate = DateTime.Now, UEIPP_ModifiedDate = DateTime.Now }; db.Tbl_UserExamInPersonPlan.Add(_UserExamInPersonPlan); _ExamInPersonPlan.EIPP_Capacity -= 1; db.Entry(_ExamInPersonPlan).State = EntityState.Modified; if (Convert.ToBoolean(db.SaveChanges() > 0)) { //if (_ExamInPersonPlan.EIPP_Capacity <= 0) //{ // TempData["TosterState"] = "warning"; // TempData["TosterType"] = TosterType.Maseage; // TempData["TosterMassage"] = "ظرفیت آزمون مورد نظر پر شده است"; // return RedirectToAction("Details", "ExamInPerson", new { area = "Dashboard", id = model.ExamID }); //} if (!walletResult && !smsResult) { TempData["TosterState"] = "warning"; TempData["TosterType"] = TosterType.WithTitel; TempData["TosterTitel"] = "خطا در ارسال پیامک"; TempData["TosterMassage"] = "کمبود موجودی کیف پول کاربر"; } else if (!walletResult) { TempData["TosterState"] = "warning"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "کمبود موجودی کیف پول کاربر"; } else if (!smsResult) { TempData["TosterState"] = "warning"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "خطا در ارسال پیامک"; } else { TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام شد"; } return(RedirectToAction("Details", "ExamInPerson", new { area = "Dashboard", id = model.ExamID })); } TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام نشد"; return(RedirectToAction("Details", "ExamInPerson", new { area = "Dashboard", id = model.ExamID })); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام نشد"; return(RedirectToAction("Details", "ExamInPerson", new { area = "Dashboard", id = model.ExamID })); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }