Beispiel #1
0
        public void DeleteMainRow(TblStyleImageViewModel row)
        {
            var res = MessageBox.Show("Are You To Delete SelectedRecords From Database ?", "Delete",
                                      MessageBoxButton.OKCancel);

            if (res == MessageBoxResult.OK)
            {
                if (row.Iserial == 0)
                {
                    MainRowList.Remove(row);
                }
                else
                {
                    Client.DeleteTblStyleImageAsync(
                        (TblStyleImage) new TblStyleImage().InjectFrom(row), MainRowList.IndexOf(row));
                }
            }
        }
Beispiel #2
0
        public StyleImageViewModel(TblStyleViewModel style)
        {
            Style       = style;
            MainRowList = new SortableCollectionView <TblStyleImageViewModel>();

            GetColors();
            MainRowList.CollectionChanged += MainRowList_CollectionChanged;
            SelectedMainRow = new TblStyleImageViewModel();

            Client.GetTblStyleImageCompleted += (s, sv) =>
            {
                MainRowList.Clear();
                foreach (var row in sv.Result)
                {
                    var newrow = new TblStyleImageViewModel();
                    newrow.InjectFrom(row);
                    newrow.ColorPerRow = row.TblColor1;
                    MainRowList.Add(newrow);
                }
                Loading = false;
            };

            Client.GetTblColorLinkCompleted += (s, sv) =>
            {
                ColorList = new ObservableCollection <TblColor>();
                foreach (var row in sv.Result)
                {
                    ColorList.Add(row.TblColor1);
                }
            };

            Client.MaxIserialOfStyleCompleted += (s, sv) =>
            {
                FolderPath = "Uploads" + "/" + sv.imagePath;

                string folderName = FolderPath + "/" + Style.SeasonPerRow.Ename + "_" + Style.Brand + "_" +
                                    Style.SectionPerRow.Ename;

                var counter = 0;
                foreach (var item in MainRowList)
                {
                    if (item.Iserial == 0)
                    {
                        var maxIserial = sv.Result;

                        item.ImagePath  = folderName + "/" + style.StyleCode + maxIserial + counter + ".png";
                        item.FolderPath = folderName;
                        item.UploadFile(item.ImagePerRow);

                        counter++;
                    }
                }

                var isvalid = false;

                foreach (var tblStyleImageViewModel in MainRowList)
                {
                    isvalid = Validator.TryValidateObject(tblStyleImageViewModel, new ValidationContext(tblStyleImageViewModel, null, null), null, true);

                    if (!isvalid)
                    {
                        return;
                    }
                }

                if (isvalid)
                {
                    var savelist = new ObservableCollection <TblStyleImage>();
                    GenericMapper.InjectFromObCollection(savelist, MainRowList);

                    Client.UpdateOrInsertTblStyleImageAsync(savelist);
                }
            };
            Client.GetTblStyleImageAsync(style.Iserial);
            Client.UpdateOrInsertTblStyleImageCompleted += (s, x) => Client.GetTblStyleImageAsync(style.Iserial);

            Client.DeleteTblStyleImageCompleted += (s, ev) =>
            {
                if (ev.Error != null)
                {
                    throw ev.Error;
                }

                var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result);
                if (oldrow != null)
                {
                    MainRowList.Remove(oldrow);
                }
            };
        }