public string ClearSuspendedDuesofCustomer(int SubCustId) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { DateTime?subExclusionDate = BL_Common.GetDatetime(); var totalpaidcustomer = db.usp_GetTotalPaidofCustomer(SubCustId).FirstOrDefault();//.Select (x => new { x.CustId, x.TotPaid, x.LastPaid }); decimal _totpaid = (totalpaidcustomer == null ? 0 : (totalpaidcustomer.TotPaid ?? 0)); var totalduesfromstart = db.usp_GetSubDuesofCustomer(SubCustId).ToList().Select(x => new { x.CustId, x.SubscriptionDueDate, x.Debit, x.AllDueBefore }).ToList(); for (int i = 0; i < totalduesfromstart.Count(); i++) { if (_totpaid <= totalduesfromstart[i].AllDueBefore) { subExclusionDate = totalduesfromstart[i].SubscriptionDueDate; //string t= "Update SubscriptionExcludingDates SET SubDisableStartDate = '" + subExclusionDate + "' where CustId = " + SubCustId+ " and SubDisableEndDate = '"+new DateTime(2015,12,31).Date.Date+"'"; db.Database.ExecuteSqlCommand("Update SubscriptionExcludingDates SET SubDisableStartDate = '" + subExclusionDate + "' where CustId=" + SubCustId + " and SubDisableEndDate= '2050 - 12 - 31 00:00:00.000'"); break; } } Func <DateTime, string> act = new Func <DateTime, string>(BL_SubscriptionManagement.ValidateDueDates); act.BeginInvoke(DateTime.Now, null, null); //var lst_totalpaid = (from GL in db.Acc_GL // join C in db.Customers on GL.CustId equals C.Id // join S in db.Subscriptions on C.Id equals S.CustId // where GL.IsActive == true && C.IsActive == true && S.IsActive == true // select new // { // tranid = GL.TranId, // credit = GL.Credit, // subDueDate = GL.SubscriptionDueDate, // debit = GL.Debit, // } // ).ToList(); //decimal totalpaid = lst_totalpaid.Sum(x => x.credit).Value; //db.Database.ExecuteSqlCommand("Update SubscriptionExcludingDates SET SubDisableStartDate = '" + BL_Common.GetDatetime() + "' where CustId=" + SubCustId); // db.Database.ExecuteSqlCommand("Update Subscription SET StartDate = '" + BL_Common.GetDatetime() + "' where Id=" + SubCustId); } //var lst_sed = db_aa.SubscriptionExcludingDates.Where(x => x.CustId == SubCustId).ToList(); //if (lst_sed != null && lst_sed.Count > 0) //{ // List<BO_SubscriptionExcludingDates> ll = new List<BO_SubscriptionExcludingDates>(); // for (int i = 0; i < lst_sed.Count; i++) // { // BO_SubscriptionExcludingDates _Sed = new BO_SubscriptionExcludingDates(); // //_Sed.subDisableStartDate = BL_Common.GetDatetime(); // //_Sed.sedisActive = true; // db_aa.SubscriptionExcludingDates.Add(_Sed); // db_aa.SaveChanges(); // } // db_aa.SaveChanges(); //} return("success"); }