public WorkSpaceViewModel() { if (CurrentUserID.ProjectID != default(int)) { DBRepository <UserProject> dBProject = new DBRepository <UserProject>(new BuildEntities()); CurrentProject = dBProject.GetAll().Where(s => s.ID == CurrentUserID.ProjectID).First(); CurrentUserID.ProjectID = default(int); DBRepository <WorkField> dBWorkField = new DBRepository <WorkField>(new BuildEntities()); DBRepository <Elements> dbElement = new DBRepository <Elements>(new BuildEntities()); foreach (var item in dBWorkField.GetAll().Where(s => s.ID_UP == CurrentProject.ID)) { try { HomeCollection.Add(new HomeElements(item, dbElement.GetAll().Where(s => s.ID == item.Element_ID).First())); TotalPrice = (Convert.ToDecimal(TotalPrice) + (decimal)item.Elements.Price).ToString(); } catch { } } dBProject.Dispose(); dBWorkField.Dispose(); dbElement.Dispose(); } BackHistory.History.Push(HomeCollection.ToList()); var windows = Application.Current.Windows; if (windows.Count > 1) { try { Window window = null; foreach (var item in windows) { if (item as Loading != null) { window = (item as Loading); } } window.Close(); } catch { } } }
private void DropSelectedIcon() { if (currentElement != null || ChangeWorkField != null) { DBRepository <Elements> dBRepository = new DBRepository <Elements>(new BuildEntities()); try { if (Choose && !Change) { int x = (int)CursorPoint.X - (int)CurrentElement.Size / 2; int y = (int)CursorPoint.Y; WorkField workField = new WorkField { Element_ID = CurrentElement.ID, Rotate = 0, PositionX = x, PositionY = y }; if (CurrentProject != null) { workField.ID_UP = CurrentProject.ID; } HomeCollection.Add(new HomeElements(workField, dBRepository.GetAll().Where(s => s.ID == CurrentElement.ID).First())); Choose = false; Change = false; ChangeWorkField = null; TotalPrice = (Convert.ToDecimal(TotalPrice) + (decimal)CurrentElement.Price).ToString(); BackHistory.History.Push(HomeCollection.ToList()); if (BackHistory.History.Count() > 30) { BuildHistory helpstack = new BuildHistory(); foreach (var item in BackHistory.History) { if (helpstack.History.Count < 30) { helpstack.History.Push(item); } } BackHistory.History.Clear(); foreach (var item in helpstack.History) { BackHistory.History.Push(item); } } } else if (Choose && Change) { HomeCollection.Remove(ChangeWorkField); int x = (int)CursorPoint.X - (int)ChangeWorkField.Element.Size / 2; int y = (int)CursorPoint.Y; ChangeWorkField.Field.PositionX = x; ChangeWorkField.Field.PositionY = y; HomeCollection.Add(ChangeWorkField); Choose = false; Change = false; ChangeWorkField = null; } } catch { } dBRepository.Dispose(); } }