public void SaveMainRow() { if (SelectedMainRow != null) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true); if (SelectedMainRow.DetailsList.Sum(x => x.Percentage) != 100) { isvalid = false; MessageBox.Show("Total Percentage Should Be !00%"); } if (isvalid) { var saveRow = new TblPaymentSchedule(); var save = SelectedMainRow.Iserial == 0; saveRow.InjectFrom(SelectedMainRow); saveRow.TblPaymentScheduleDetails = new ObservableCollection <TblPaymentScheduleDetail>(); GenericMapper.InjectFromObCollection(saveRow.TblPaymentScheduleDetails, SelectedMainRow.DetailsList); Client.UpdateOrInsertTblPaymentScheduleAsync(saveRow, save, MainRowList.IndexOf(SelectedMainRow)); } } }
private int DeleteTblPaymentSchedule(TblPaymentSchedule row) { using (var context = new WorkFlowManagerDBEntities()) { var oldRow = (from e in context.TblPaymentSchedules where e.Iserial == row.Iserial select e).SingleOrDefault(); if (oldRow != null) { context.DeleteObject(oldRow); } context.SaveChanges(); } return(row.Iserial); }
private TblPaymentSchedule UpdateOrInsertTblPaymentSchedule(TblPaymentSchedule newRow, bool save, int index, out int outindex) { outindex = index; using (var context = new WorkFlowManagerDBEntities()) { if (save) { foreach (var row in newRow.TblPaymentScheduleDetails.ToList()) { row.TblPaymentScheduleSetting = null; } context.TblPaymentSchedules.AddObject(newRow); } else { var oldRow = (from e in context.TblPaymentSchedules where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { GenericUpdate(oldRow, newRow, context); } foreach (var row in newRow.TblPaymentScheduleDetails.ToList()) { var oldDetailRow = (from e in context.TblPaymentScheduleDetails where e.Iserial == row.Iserial select e).SingleOrDefault(); if (oldDetailRow != null) { GenericUpdate(oldDetailRow, row, context); } else { row.TblPaymentSchedule1 = null; row.TblPaymentScheduleSetting = null; context.TblPaymentScheduleDetails.AddObject(row); } } } context.SaveChanges(); return(newRow); } }