public void AddNewMainRow(bool checkLastRow) { var currentRowIndex = (MainRowList.IndexOf(SelectedMainRow)); if (!checkLastRow || currentRowIndex == (MainRowList.Count - 1)) { if (checkLastRow) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true); if (!isvalid) { return; } } var newRow = new TblBrandSectionMailViewModel { TblBrand = Brand, TblLkpBrandSection = BrandSection }; MainRowList.Insert(currentRowIndex + 1, newRow); } }
public BrandSectionMailViewModel() { if (!DesignerProperties.IsInDesignTool) { Client.GetAllBrandsAsync(LoggedUserInfo.Iserial); Client.GetAllBrandsCompleted += (d, s) => { BrandList = s.Result; }; lkpClient.GetTblBrandSectionLinkCompleted += (s, sv) => { BrandSectionList.Clear(); foreach (var row in sv.Result) { BrandSectionList.Add(row.TblLkpBrandSection1); } }; MainRowList = new SortableCollectionView <TblBrandSectionMailViewModel>(); SelectedMainRow = new TblBrandSectionMailViewModel(); Client.GetTblBrandSectionMailCompleted += (s, sv) => { foreach (var row in sv.Result) { var newrow = new TblBrandSectionMailViewModel(); newrow.InjectFrom(row); var newEmp = sv.EmpList.FirstOrDefault(x => x.EMPLID == newrow.Emp); if (newEmp != null) { newrow.EmpPerRow = new EmployeesView { Emplid = newEmp.EMPLID, Name = newEmp.name } } ; MainRowList.Add(newrow); } Loading = false; if (MainRowList.Count == 0) { AddNewMainRow(false); } }; Client.UpdateOrInsertTblBrandSectionMailCompleted += (s, x) => { var savedRow = (TblBrandSectionMailViewModel)MainRowList.GetItemAt(x.outindex); if (savedRow != null) { savedRow.InjectFrom(x.Result); } }; Client.DeleteTblBrandSectionMailCompleted += (s, ev) => { if (ev.Error != null) { throw ev.Error; } var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result.Iserial); if (oldrow != null) { MainRowList.Remove(oldrow); } }; GetMaindata(); } }