private void BindSelectedStockDetails(StockDetail selectedstock)
 {
     var stock = selectedstock as StockDetail;
     if (stock != null)
     {
         SetEntryValuesforEdit(stock);
     }
 }
 private void RaiseConfirmation(StockDetail delstock)
 {
     this.ConfirmationRequest.Raise(
         new Confirmation { Content = delstock, Title = "Please click OK to Delete?" },
         c =>
         {
             if (c.Confirmed)
             {
                 var _delstock = c.Content as StockDetail;
                 if (this.fundsDataService.DeleteStockDetails(_delstock))
                 {
                     this.eventAggregator.GetEvent<StockUpdatedEvent>().Publish(string.Empty);
                     this.eventAggregator.GetEvent<UpdateStockSummary>().Publish(default(object));
                     this.eventAggregator.GetEvent<CancelStockSelectedEvent>().Publish(default(object));
                 }
             }
         }
         );
 }
        public void BlotterViewModel_Loading()
        {
            var factory = new MockRepository(MockBehavior.Loose);
            int userId = 1;
            Mock<IEventAggregator> mockEventAggtr = new Mock<IEventAggregator>();
            Mock<IFundsDataService> mockFundService = new Mock<IFundsDataService>();
            var mockStockUpdatedEventEvent = new Mock<StockUpdatedEvent>();
            var mockCancelStockSelectedEventEvent = new Mock<CancelStockSelectedEvent>();
            mockEventAggtr.Setup(e => e.GetEvent<StockUpdatedEvent>()).Returns(mockStockUpdatedEventEvent.Object);
            mockEventAggtr.Setup(e => e.GetEvent<CancelStockSelectedEvent>()).Returns(mockCancelStockSelectedEventEvent.Object);
            var stockobject = new StockDetail(){StockId=1,Type="Equity",Price=25,Quantity=10,StockName="Equity1"};
            mockFundService.Setup(t => t.GetAllStocks(userId)).Returns(new List<StockDetail>() {stockobject });
            var viewModel = new BlotterViewModel(mockFundService.Object, mockEventAggtr.Object);

            
            Assert.IsNotNull(viewModel.Stocks);
            Assert.IsTrue(viewModel.Stocks.Contains(stockobject));
            mockFundService.Verify(s => s.GetAllStocks(It.IsAny<int>()), Times.Once);
            mockEventAggtr.Verify(s => s.GetEvent<StockUpdatedEvent>(), Times.Once);
            mockEventAggtr.Verify(s => s.GetEvent<CancelStockSelectedEvent>(), Times.Once);
            factory.Verify();
            
        }
        public bool DeleteStockDetails(StockDetail stock)
        {
            try
            {
                using (var entityrepo = new UBSFundsDBEntities())
                {
                    var delStock = entityrepo.tblStocks.Find(stock.StockId);
                    if (stock != null)
                    {
                        entityrepo.tblStocks.Remove(delStock);
                        entityrepo.SaveChanges();
                        return true;
                    }
                    return false;
                }

            }
            catch (Exception ex)
            {
                return false;
            }
            
        }
 private void SetEntryValuesforEdit(StockDetail stock)
 {
     StockAction = stock.StockId.ToString();
     Price = (float) stock.Price;
     Quantity = stock.Quantity;
     SelectedStockTypeId = stock.StockTypeId;
     IsSelectable = false;
     this.OnPropertyChanged("IsSelectable");
     this.OnPropertyChanged("SelectedStockTypeId");
     this.OnPropertyChanged("Quantity");
     this.OnPropertyChanged("Price");
     this.OnPropertyChanged("StockAction");
 }