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 TblBrandSectionMailSampleViewModel {
                    TblBrand = Brand, TblLkpBrandSection = BrandSection
                };

                MainRowList.Insert(currentRowIndex + 1, newRow);
            }
        }
        public BrandSectionMailSampleViewModel()
        {
            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 <TblBrandSectionMailSampleViewModel>();
                SelectedMainRow = new TblBrandSectionMailSampleViewModel();

                Client.GetTblBrandSectionMailSampleCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblBrandSectionMailSampleViewModel();
                        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
                            }
                        }
                        ;
                        newrow.RequestForSampleStatusPerRow = row.TblRequestForSampleStatu;
                        MainRowList.Add(newrow);
                    }
                    Loading = false;

                    if (MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                };

                Client.GetTblRequestForSampleStatusAsync();

                Client.GetTblRequestForSampleStatusCompleted += (s, sv) =>
                {
                    RequestForSampleStatusList = sv.Result;
                };

                Client.UpdateOrInsertTblBrandSectionMailSampleCompleted += (s, x) =>
                {
                    var savedRow = (TblBrandSectionMailSampleViewModel)MainRowList.GetItemAt(x.outindex);

                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                    }
                };
                Client.DeleteTblBrandSectionMailSampleCompleted += (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();
            }
        }