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; } } }