private MemberFeePaymentViewModel GetMemberFeePaymentViewModel(Guid IMemberID, DateTime FromDate, DateTime ToDate)
        {
            var viewModel = new MemberFeePaymentViewModel
            {
                MemberFeePayment = _entities.MemberFeePayments.Single(a => a.IMemberID == IMemberID && a.FromDate == FromDate && a.ToDate == ToDate),
                MemberInfos      = BlackListMemberController.GetMemberNameSelectList(IMemberID),
                PayMethod        = _entities.PayMethods.ToList(),
            };

            return(viewModel);
        }
        private MemberFeePaymentViewModel GetMemberFeePaymentViewModel()
        {
            var viewModel = new MemberFeePaymentViewModel
            {
                MemberFeePayment = new MemberFeePayment(),
                MemberInfos      = BlackListMemberController.GetMemberNameSelectList(Guid.Empty),
                PayMethod        = _entities.PayMethods.ToList(),
            };

            return(viewModel);
        }
        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));
            }
        }