public ActionResult Create(FormCollection collection, MemberFeePayment memberFeePayment) { memberFeePayment.IMemberID = Guid.Parse(collection.Get("MemberFeePayment.IMemberID")); memberFeePayment.ReceivedDate = DateTime.Now.ToUniversalTime().AddHours(8); if (memberFeePayment.PayMethodID == 1) { memberFeePayment.ToDate = new DateTime(2020, 12, 31); } try { if (_entities.MemberFeePayments.Any(a => a.IMemberID == memberFeePayment.IMemberID && (memberFeePayment.FromDate >= a.FromDate && memberFeePayment.ToDate <= a.ToDate))) { ModelState.AddModelError(string.Empty, "There is a record in this period already for this initiate!"); throw new Exception(); } _entities.AddToMemberFeePayments(memberFeePayment); _entities.SaveChanges(); SaveLatestMemberFeeToDateToMemberInfo(memberFeePayment.IMemberID); return(RedirectToAction("Index")); } catch { var viewModel = new MemberFeePaymentViewModel { MemberFeePayment = memberFeePayment, MemberInfos = BlackListMemberController.GetMemberNameSelectList(memberFeePayment.IMemberID), PayMethod = _entities.PayMethods.ToList(), }; //var viewModel = GetMemberFeePaymentViewModel(); return(View(viewModel)); } }