public static string DeleteSubscriptionCustomer(int subcustomerID) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { var custTransaction = (from cust in db.Customers join sub in db.Subscriptions on cust.Id equals sub.CustId join Gl in db.Acc_GL on cust.Id equals Gl.CustId where sub.Id == subcustomerID && Gl.IsActive == true select new { Id = sub.Id }).ToList(); // var custTransaction = db.Acc_GL.Where(x => x.CustId == subcustomerID && x.IsActive == true).ToList();// && x.Quantity == x.QuantityBalance).ToList(); if (custTransaction == null || custTransaction.Count > 0) { return("Transaction is Performed against this Customer, it can not be deleted "); } var obj = db.Subscriptions.Where(x => x.Id == subcustomerID).FirstOrDefault(); obj.ModifiedBy = 1; obj.ModifiedOn = BL_Common.GetDatetime(); obj.IsActive = false; db.SaveChanges(); //var cus = db.Customers.Where(x => x.Id == obj.CustId).FirstOrDefault(); //cus.ModifiedBy = 1; //cus.ModifiedOn = BL_Common.GetDatetime(); //cus.IsActive = false; //db.SaveChanges(); return("success"); } }
public static string DeleteItem(int _itemId, int userID) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { var vendTransaction = db.Acc_GL.Where(x => x.ItemId == _itemId && x.IsActive == true).ToList();// && x.Quantity == x.QuantityBalance).ToList(); if (vendTransaction == null || vendTransaction.Count > 0) { return("Transaction is Performed against Item, it can not be deleted "); } var obj = db.Items.Where(x => x.Id == _itemId).FirstOrDefault(); if (obj != null && obj.Id > 0) { obj.ModifiedBy = userID; obj.ModifiedOn = BL_Common.GetDatetime(); } obj.IsActive = false; // db.Items.Add(obj); db.SaveChanges(); return("success"); } }
public static string SaveSalesPerson(BO_SalesPersonManagement _salesPerson, int UserID) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { try { var obj = _salesPerson.Id == 0 ? new ApprosysAccDB.SalesPerson() : db.SalesPersons.Where(x => x.Id == _salesPerson.Id && x.IsActive == true).FirstOrDefault(); if (_salesPerson.Id > 0) { var checkCust = db.SalesPersons.Where(x => x.LastName.ToLower() == _salesPerson.lastName.ToLower() && x.FirstName.ToLower() == _salesPerson.firstName.ToLower() && x.Id != _salesPerson.Id && x.IsActive == true).FirstOrDefault(); if (checkCust != null) { return("Sales Person Already Exists"); } } if (obj != null && obj.Id > 0) { obj.ModifiedBy = UserID; obj.ModifiedOn = BL_Common.GetDatetime(); var customerList = db.Customers.Where(c => c.SalesPersonId == obj.Id && c.IsActive == true).ToList(); if (customerList != null) { foreach (var item in customerList) { item.SalesPersonId = null; } } } obj.Id = _salesPerson.Id; obj.LastName = _salesPerson.lastName; obj.FirstName = _salesPerson.firstName; obj.Phone = _salesPerson.phone ?? ""; obj.Email = _salesPerson.email; obj.CNIC = _salesPerson.cnic; obj.NTN = _salesPerson.ntn; if (_salesPerson.startDate == null) { _salesPerson.startDate = DateTime.Now.Date; } obj.StartDate = _salesPerson.startDate; obj.OpeningBalance = _salesPerson.openingBalance; obj.Misc = _salesPerson.misc; if (obj.Id == 0) { obj.CreatedBy = UserID; obj.CreatedOn = BL_Common.GetDatetime(); var objcheck = db.SalesPersons.Where(x => x.LastName.ToLower() == _salesPerson.lastName.ToLower() && x.FirstName.ToLower() == _salesPerson.firstName.ToLower() && x.IsActive == true).FirstOrDefault(); if (objcheck != null) { return("Sales Person Already Exists"); } db.SalesPersons.Add(obj); } obj.IsActive = true; db.SaveChanges(); if (_salesPerson.customersIDs != null) { var customerList = db.Customers.Where(c => _salesPerson.customersIDs.Contains(c.Id) && c.IsActive == true).ToList(); foreach (var item in customerList) { item.SalesPersonId = obj.Id; } db.SaveChanges(); } return(obj.Id.ToString()); // return "Insertion Failed"; } catch { throw; } } }
public static BO_ReceiptVoucher GetReceiptVoucherByInvoiceId(int custType, string _rvoucherInvoiceId) { BO_ReceiptVoucher _rvoucher = new BussinessObject.BO_ReceiptVoucher(); using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { if (custType == 1) { var obj = db.GetReceiptVoucherListByVoucherNO(_rvoucherInvoiceId, 0).ToList(); if (obj != null) { #region voucher object _rvoucher.invoiceNo = obj[0].InvoiceNo; _rvoucher.rActivityDate = obj[0].ActivityTimestamp ?? BL_Common.GetDatetime(); _rvoucher.TypeId = 1; _rvoucher.rCustomerId = obj[0].CustId; _rvoucher.rRecived = obj[0].Amount ?? 0; _rvoucher.rComments = obj[0].Comments ?? ""; _rvoucher.rGrossAmount = 1; _rvoucher.rbalance = BL_Customer.GetCustomerBalance(obj[0].CustId) ?? 0; #endregion } } if (custType == 2) { var obj = db.GetSubscriptionByVoucherNo(_rvoucherInvoiceId).ToList(); { if (obj != null) { #region voucher object _rvoucher.invoiceNo = obj[0].InvoiceNo; _rvoucher.rActivityDate = obj[0].ActivityTimestamp ?? BL_Common.GetDatetime(); _rvoucher.TypeId = 2; _rvoucher.rCustomerId = obj[0].CustId; _rvoucher.rRecived = obj[0].Amount ?? 0; _rvoucher.rComments = obj[0].Comments ?? ""; _rvoucher.rGrossAmount = 1; _rvoucher.rbalance = BL_Customer.GetCustomerBalance(obj[0].CustId) ?? 0; _rvoucher.DueDate = BL_Customer.GetSubCustomerList(2).Where(x => x.Id == obj[0].CustId).FirstOrDefault().DueDate; _rvoucher.rSubscriptionAmount = obj[0].SubscriptionAmount; #endregion } } } return(_rvoucher); } }
public static string SaveItem(BO_Item _item, int userId) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { try { //var objcheck = db.Items.Where(x => x.ItemCode.ToLower() == _item.itemCode.ToLower() || x.Name.ToLower() == _item.name.ToLower()).FirstOrDefault(); //if (objcheck != null && _item.id == 0) //{ // if (objcheck.ItemCode == _item.itemCode) // { // return "Code Already Exists"; // } // if (objcheck.Name == _item.name) // { // return "Name Already Exists"; // } //} var obj = _item.id == 0 ? new ApprosysAccDB.Item() : db.Items.Where(x => x.Id == _item.id).FirstOrDefault(); if (_item.id > 0) { var checkCust = db.Items.Where(x => x.Id != _item.id && x.IsActive == true && (x.Name.ToLower() == _item.name.ToLower() || x.ItemCode.ToLower() == _item.itemCode.ToLower())).FirstOrDefault(); if (checkCust != null) { if (checkCust.ItemCode.ToLower() == _item.itemCode.ToLower()) { return("Code Already Exists"); } if (checkCust.Name.ToLower() == _item.name.ToLower()) { return("Name Already Exists"); } } } if (obj != null && obj.Id > 0) { obj.ModifiedBy = userId; obj.ModifiedOn = BL_Common.GetDatetime(); } obj.Id = _item.id; obj.ItemTypeId = 1; obj.Name = _item.name; obj.ItemCode = _item.itemCode ?? ""; obj.MinQty = _item.minQuantity; obj.Unit = _item.unit; obj.PurchasePrice = _item.purchasePrice; obj.SellPrice = _item.sellPrice; obj.TaxPercent = _item.taxPercent; obj.Description = _item.description; obj.IsActive = true; obj.IsTaxable = _item.isTaxable; obj.OilGradeId = _item.oilGradeId; obj.QuantityInCarton = _item.quantityInCarton; obj.PackingInLitre = _item.packingInLitre; if (_item.id == 0) { obj.CreatedBy = userId; obj.CreatedOn = BL_Common.GetDatetime(); var objcheck = db.Items.Where(x => x.Id != _item.id && x.IsActive == true && (x.Name.ToLower() == _item.name.ToLower() || x.ItemCode.ToLower() == _item.itemCode.ToLower())).FirstOrDefault(); if (objcheck != null) { if (objcheck.ItemCode.ToLower() == _item.itemCode.ToLower()) { return("Code Already Exists"); } if (objcheck.Name.ToLower() == _item.name.ToLower()) { return("Name Already Exists"); } } db.Items.Add(obj); } db.SaveChanges(); return("success"); } catch { throw; } } }
public static string SaveVendor(BO_Vendor _vendor, int userId) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { try { //var objcheck = db.Vendors.Where(x => x.LastName.ToLower() == _vendor.lastName.ToLower() && x.FirstName.ToLower() == _vendor.firstName.ToLower()).FirstOrDefault(); //if (objcheck != null) //{ // return "Vendor Already Exists"; //} var obj = _vendor.id == 0 ? new ApprosysAccDB.Vendor() : db.Vendors.Where(x => x.ID == _vendor.id && x.IsActive == true).FirstOrDefault(); //bool isVendorModified = false; // if (obj != null && obj.ID > 0) { isVendorModified = IsVendorModified(_vendor, obj); } if (_vendor.id > 0) { var checkCust = db.Vendors.Where(x => x.LastName.ToLower() == _vendor.lastName.ToLower() && x.FirstName.ToLower() == _vendor.firstName.ToLower() && x.ID != _vendor.id && x.IsActive == true).FirstOrDefault(); if (checkCust != null) { return("Vendor Already Exists"); } } if (obj != null && obj.ID > 0) { obj.ModifiedBy = userId; obj.ModifiedOn = BL_Common.GetDatetime(); } obj.ID = _vendor.id; obj.LastName = _vendor.lastName; obj.FirstName = _vendor.firstName; obj.Phone = _vendor.phone ?? ""; obj.Email = _vendor.email; obj.Terms = _vendor.terms; obj.CreditLimit = _vendor.creditLimit; obj.Balance = _vendor.balance; obj.Misc = _vendor.misc; obj.IsActive = true; obj.CNIC = _vendor.cnic; obj.NTN = _vendor.ntn; if (obj.ID == 0) { obj.CreatedBy = userId; obj.CreatedOn = BL_Common.GetDatetime(); var objcheck = db.Vendors.Where(x => x.LastName.ToLower() == _vendor.lastName.ToLower() && x.FirstName.ToLower() == _vendor.firstName.ToLower() && x.IsActive == true).FirstOrDefault(); if (objcheck != null) { return("Vendor Already Exists"); } db.Vendors.Add(obj); } db.SaveChanges(); return("success"); // return "Insertion Failed"; } catch { throw; } } }
public static string SaveSubscriptionCustomer(BO_SubCustomer _Subcustomer, int userid) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { try { //var objcheck = db.Customers.Where(x => x.LastName.ToLower() == _Subcustomer.lastName.ToLower() && x.FirstName.ToLower() == _Subcustomer.firstName.ToLower()).FirstOrDefault(); //if (objcheck != null) //{ // return "Customer Already Exists"; //} var objcheck = db.Subscriptions.Where(x => x.CustId == _Subcustomer.id && x.IsActive == true).FirstOrDefault(); if (objcheck != null) { return("Customer Already Exists"); } var obj = _Subcustomer.id == 0 ? new ApprosysAccDB.Customer() : db.Customers.Where(x => x.Id == _Subcustomer.id).FirstOrDefault(); //if (obj != null && obj.Id > 0) //{ // obj.ModifiedBy = _Subcustomer.modifiedBy; // obj.ModifiedOn = BL_Common.GetDatetime(); //} //obj.Id = _Subcustomer.id; //obj.LastName = _Subcustomer.lastName; //obj.FirstName = _Subcustomer.firstName; //obj.Phone = _Subcustomer.phone ?? ""; //obj.Email = _Subcustomer.email; //obj.StartDate = _Subcustomer.startDate; //obj.OpeningBalance = _Subcustomer.openingBalance; //obj.Misc = _Subcustomer.misc; //obj.TypeId = 2; //obj.CreatedBy = userid; //obj.CreatedOn = BL_Common.GetDatetime(); //obj.IsActive = true; //db.Customers.Add(obj); //db.SaveChanges(); var objsub = _Subcustomer.id != 0 ? new ApprosysAccDB.Subscription() : db.Subscriptions.Where(x => x.Id == _Subcustomer.subid).FirstOrDefault(); // objsub.Id = _Subcustomer.subid; //objsub.CustId = obj.Id; objsub.CustId = _Subcustomer.id; objsub.SubscriptionAmount = _Subcustomer.subscriptionAmount; objsub.DueDate = _Subcustomer.dueDate; objsub.StartDate = _Subcustomer.startDate ?? BL_Common.GetDatetime(); obj.CreatedOn = BL_Common.GetDatetime(); obj.CreatedBy = userid; objsub.IsActive = true; obj.Misc = _Subcustomer.misc; objsub.SubStatus = _Subcustomer.subStatus; db.Subscriptions.Add(objsub); db.SaveChanges(); if (_Subcustomer.subStatus) { var obj1 = new ApprosysAccDB.SubscriptionExcludingDate(); obj1.CustId = objsub.Id; obj1.SubDisableStartDate = BL_Common.GetDatetime(); obj1.SubDisableEndDate = new DateTime(2050, 12, 31); obj1.IsActive = true; db.SubscriptionExcludingDates.Add(obj1); db.SaveChanges(); /*if (_Subcustomer.sed != null && _Subcustomer.sed.Count > 0) * { * for (int i = 0; i < _Subcustomer.sed.Count; i++) * { * try * { * var obj1 = new ApprosysAccDB.SubscriptionExcludingDate(); * obj1.CustId = objsub.Id; * obj1.SubDisableStartDate = _Subcustomer.sed[i].subDisableStartDate; * obj1.SubDisableEndDate = _Subcustomer.sed[i].subDisableEndDate; * obj1.IsActive = true; * db.SubscriptionExcludingDates.Add(obj1); * db.SaveChanges(); * } * catch (Exception ex) * { } * } * } */ } //db.SaveChanges(); Func <DateTime, string> act = new Func <DateTime, string>(BL_SubscriptionManagement.ValidateDueDates); act.BeginInvoke(DateTime.Now, null, null); return("success"); // return "Insertion Failed"; } catch (Exception ex) { throw; } } }
public static string EditSubscriptionCustomer(BO_SubCustomer _Subcustomer, int userid) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { try { //var objcheck = db.Customers.Where(x => x.LastName.ToLower() == _Subcustomer.lastName.ToLower() && x.FirstName.ToLower() == _Subcustomer.firstName.ToLower()).FirstOrDefault(); //if (objcheck != null) //{ // return "Customer Already Exists"; //} var objsub = db.Subscriptions.Where(x => x.Id == _Subcustomer.id).FirstOrDefault(); objsub.CustId = objsub.CustId; objsub.SubscriptionAmount = _Subcustomer.subscriptionAmount; objsub.DueDate = _Subcustomer.dueDate; objsub.StartDate = _Subcustomer.startDate ?? BL_Common.GetDatetime(); objsub.ModifiedOn = BL_Common.GetDatetime(); objsub.ModifiedBy = userid; objsub.IsActive = true; objsub.SubStatus = _Subcustomer.subStatus; if (!_Subcustomer.subStatus) { var obj1 = db.SubscriptionExcludingDates.Where(x => x.CustId == _Subcustomer.id && x.SubDisableEndDate == new DateTime(2050, 12, 31)).FirstOrDefault(); if (obj1 != null && obj1.SubDisableEndDate.Value.Date == new DateTime(2050, 12, 31).Date) { obj1.SubDisableEndDate = BL_Common.GetDatetime(); db.SaveChanges(); } } if (_Subcustomer.subStatus) { var obj1 = db.SubscriptionExcludingDates.Where(x => x.CustId == _Subcustomer.id).FirstOrDefault(); if (obj1 != null && obj1.SubDisableEndDate.Value.Date == new DateTime(2050, 12, 31).Date) { obj1.SubDisableStartDate = BL_Common.GetDatetime(); db.SaveChanges(); } else { var obj2 = new ApprosysAccDB.SubscriptionExcludingDate(); obj2.CustId = objsub.Id; obj2.SubDisableStartDate = BL_Common.GetDatetime(); obj2.SubDisableEndDate = new DateTime(2050, 12, 31); obj2.IsActive = true; db.SubscriptionExcludingDates.Add(obj2); db.SaveChanges(); } } var obj = db.Customers.Where(x => x.Id == objsub.CustId).FirstOrDefault(); obj.ModifiedBy = userid; obj.ModifiedOn = BL_Common.GetDatetime(); obj.Misc = _Subcustomer.misc; db.SaveChanges(); Func <DateTime, string> act = new Func <DateTime, string>(BL_SubscriptionManagement.ValidateDueDates); act.BeginInvoke(DateTime.Now, null, null); return("success"); // return "Insertion Failed"; } catch (Exception ex) { throw; } } }
public static string ValidateDueDates(DateTime actingDate) { lock (objLck) { using (AprosysAccountingEntities db = new AprosysAccountingEntities()) { Appcode.Logger.Write("Subscription Routine", "ValidateDueDates", "DateTime: " + actingDate.ToString() + " ," + actingDate.ToString(), Appcode.Logger.LogType.InformationLog); // var custl = db.Customers.Where(x => x.TypeId == 2 && x.IsActive == true).Select(x => x.Id).ToList(); var custl = (from t1 in db.Customers.Where(x => x.IsActive == true) join t2 in db.Subscriptions.Where(s => s.IsActive == true) on t1.Id equals t2.CustId select t1.Id).ToList(); var subsl = db.Subscriptions.Where(x => x.IsActive == true).ToList(); var subexcdates = (from s in db.Subscriptions join e in db.SubscriptionExcludingDates on s.CustId equals e.CustId select new { e.CustId, e.SubDisableStartDate, e.SubDisableEndDate }).ToList(); int transType = (int)Constants.TransactionTypes.SubscriptionDue; var glList = db.Acc_GL.Where(x => x.TranTypeId == transType && x.IsActive == true && x.CoaId == 10).Select(x => new { x.GlId, x.CustId, x.SubscriptionDueDate }).ToList();//.ToList().Where(x => x.ActivityTimestamp.Value.Date.Month == BL_Common.GetDatetime().Month && x.ActivityTimestamp.Value.Date.Year == BL_Common.GetDatetime().Year).Select(x => new { x.GlId, x.CustId, x.ActivityTimestamp }).ToList(); glList = glList.Where(x => custl.Contains(x.CustId.Value)).ToList(); //if (glList.Count == 0) { return "Ledger is empty"; } foreach (var cust in custl) { var sub = subsl.SingleOrDefault(x => x.CustId == cust); var subStartDate = sub.StartDate; while (subStartDate <= new DateTime(actingDate.Year, actingDate.Month, DateTime.DaysInMonth(actingDate.Year, actingDate.Month))) { // do something with target.Month and target.Year var monthDue = subStartDate; var dueDate = new DateTime(monthDue.Year, monthDue.Month, sub.DueDate); if ((/*(monthDue.Month < DateTime.Now.Month && monthDue < DateTime.Now) ||*/ (dueDate <= actingDate.Date && dueDate >= sub.StartDate)) && !glList.Exists(x => x.CustId == cust && x.SubscriptionDueDate.Value.Month == dueDate.Month && x.SubscriptionDueDate.Value.Year == dueDate.Year)) { // Need to add a check which stops Excluding Entries in Acc_GL , however theese entries is removed in Exclusion Region if (sub.SubStatus == true) { var subExclusionsDates = db.SubscriptionExcludingDates.Where(x => x.CustId == sub.Id && x.IsActive == true).ToList(); if (subExclusionsDates != null && subExclusionsDates.Count > 0) { DateTime _startdisabledate = subExclusionsDates[0].SubDisableStartDate ?? BL_Common.GetDatetime(); DateTime _enddisabledate = subExclusionsDates[0].SubDisableEndDate ?? BL_Common.GetDatetime(); if (dueDate < _startdisabledate) { #region Insertion into AccGL using (var transaction = db.Database.BeginTransaction()) { try { var vNo = GetNextVoucher(); //if (!(sub.SubStatus == true && dueDate > sub.SubDisableStartDate && dueDate < sub.SubDisableEndDate)) // if (!(sub.SubStatus == true && dueDate > subexcdates.Where( x=>x.SubDisableStartDate > dueDate).FirstOrDefault() && dueDate < sub.SubDisableEndDate)) { //Parent Entry var GLParent = new Acc_GL() { CoaId = 0, CustId = cust, ActivityTimestamp = actingDate, SubscriptionDueDate = dueDate, TranTypeId = transType, Debit = sub.SubscriptionAmount, Credit = sub.SubscriptionAmount, InvoiceNo = vNo, IsActive = true, CreatedDate = actingDate, CreatedBy = 1, ModifiedBy = 1, ModifiedDate = actingDate }; db.Acc_GL.Add(GLParent); db.SaveChanges(); //Account Receivable var GLRec = new Acc_GL() { TranId = GLParent.GlId, CoaId = 10, CustId = cust, ActivityTimestamp = actingDate, SubscriptionDueDate = dueDate, TranTypeId = transType, Debit = sub.SubscriptionAmount, InvoiceNo = vNo, IsActive = true, IsPostpaid = true, CreatedDate = actingDate, CreatedBy = 1, ModifiedBy = 1, ModifiedDate = actingDate }; db.Acc_GL.Add(GLRec); //Subscription Sales var GLSubSales = new Acc_GL() { TranId = GLParent.GlId, CoaId = 100, CustId = cust, ActivityTimestamp = actingDate, SubscriptionDueDate = dueDate, TranTypeId = transType, Credit = sub.SubscriptionAmount, InvoiceNo = vNo, IsActive = true, IsPostpaid = true, CreatedDate = actingDate, CreatedBy = 1, ModifiedBy = 1, ModifiedDate = actingDate }; db.Acc_GL.Add(GLSubSales); db.SaveChanges(); } transaction.Commit(); } catch (Exception ex) { Appcode.Logger.Write("Subscription Routine", "Validate Due Dates", ex.ToString(), Appcode.Logger.LogType.ErrorLog); transaction.Rollback(); throw; } } #endregion } } } else { #region Insertion into AccGL using (var transaction = db.Database.BeginTransaction()) { try { var vNo = GetNextVoucher(); //if (!(sub.SubStatus == true && dueDate > sub.SubDisableStartDate && dueDate < sub.SubDisableEndDate)) // if (!(sub.SubStatus == true && dueDate > subexcdates.Where( x=>x.SubDisableStartDate > dueDate).FirstOrDefault() && dueDate < sub.SubDisableEndDate)) { //Parent Entry var GLParent = new Acc_GL() { CoaId = 0, CustId = cust, ActivityTimestamp = actingDate, SubscriptionDueDate = dueDate, TranTypeId = transType, Debit = sub.SubscriptionAmount, Credit = sub.SubscriptionAmount, InvoiceNo = vNo, IsActive = true, CreatedDate = actingDate, CreatedBy = 1, ModifiedBy = 1, ModifiedDate = actingDate }; db.Acc_GL.Add(GLParent); db.SaveChanges(); //Account Receivable var GLRec = new Acc_GL() { TranId = GLParent.GlId, CoaId = 10, CustId = cust, ActivityTimestamp = actingDate, SubscriptionDueDate = dueDate, TranTypeId = transType, Debit = sub.SubscriptionAmount, InvoiceNo = vNo, IsActive = true, IsPostpaid = true, CreatedDate = actingDate, CreatedBy = 1, ModifiedBy = 1, ModifiedDate = actingDate }; db.Acc_GL.Add(GLRec); //Subscription Sales var GLSubSales = new Acc_GL() { TranId = GLParent.GlId, CoaId = 100, CustId = cust, ActivityTimestamp = actingDate, SubscriptionDueDate = dueDate, TranTypeId = transType, Credit = sub.SubscriptionAmount, InvoiceNo = vNo, IsActive = true, IsPostpaid = true, CreatedDate = actingDate, CreatedBy = 1, ModifiedBy = 1, ModifiedDate = actingDate }; db.Acc_GL.Add(GLSubSales); db.SaveChanges(); } transaction.Commit(); } catch (Exception ex) { Appcode.Logger.Write("Subscription Routine", "Validate Due Dates", ex.ToString(), Appcode.Logger.LogType.ErrorLog); transaction.Rollback(); throw; } } #endregion } } subStartDate = subStartDate.AddMonths(1); } // if (sub.SubStatus == true) { #region Exclusion work var subExclusionsDates = db.SubscriptionExcludingDates.Where(x => x.CustId == sub.Id && x.IsActive == true).ToList(); if (subExclusionsDates != null && subExclusionsDates.Count > 0) { for (int i = 0; i < subExclusionsDates.Count; i++) { DateTime _startdisabledate = subExclusionsDates[i].SubDisableStartDate ?? BL_Common.GetDatetime(); DateTime _enddisabledate = subExclusionsDates[i].SubDisableEndDate ?? BL_Common.GetDatetime(); var subDeactive = db.Acc_GL.Where(x => (x.SubscriptionDueDate >= _startdisabledate) && (x.SubscriptionDueDate < _enddisabledate) && (x.IsActive == true) && (x.CustId == cust)).ToList(); if (subDeactive != null && subDeactive.Count > 0) { for (int j = 0; j < subDeactive.Count; j++) { subDeactive[j].IsActive = false; subDeactive[j].Comments = "Disabled From Routine by Disable Feature"; db.SaveChanges(); } } } } #endregion } } return("success"); } } }