Ejemplo n.º 1
0
        public async Task <ActionResult> Index()
        {
            var traderId = this.GetTraderId();

            var viewModel = new OrdersIndexViewModel
            {
                OrdersRequestSettings = await _clientSettingsRepository.GetSettings <OrdersRequestSettings>(traderId)
            };

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Index(PagerParameters pagerParameters)
        {
            var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);

            var myOrders = _ordersService.GetMyOrders();

            var model = new OrdersIndexViewModel()
            {
                Orders = myOrders.Skip(pager.GetStartIndex()).Take(pager.PageSize)
                         .Select(order => _contentManager.BuildDisplay(order.ContentItem, "Summary")),
                Pager = Shape.Pager(pager).TotalItemCount(myOrders.Count())
            };

            return(View(model));
        }
        public void Index_WhenCalled_ShouldReturnOK()
        {
            //Initial
            var _mockBookMarkletHelper = new Mock <Controller>();
            var config        = new MapperConfiguration(c => c.AddProfile(new MappingProfile()));
            var mapper        = config.CreateMapper();
            var unitOfWork    = new UnitOfWork(_context);
            var emailHelper   = new EmailHelper();
            var accountHelper = new AccountHelper(emailHelper);

            //creating 2 orders
            var orders = Odin.Data.Builders.OrderBuilder.New(2);

            orders.ForEach(o => o.ConsultantId     = _dsc.Id);
            orders.ForEach(o => o.TransfereeId     = _transferee.Id);
            orders.ForEach(o => o.ProgramManagerId = _pm.Id);
            orders.ForEach(o => o.TrackingId       = TokenHelper.NewToken());
            var testDateTime = new DateTime(1999, 6, 14);

            orders.ForEach(o => o.PreTripDate = testDateTime);

            _controller = new OrdersController(unitOfWork, mapper, accountHelper);
            _context.Orders.AddRange(orders);
            _controller.MockCurrentUser(_dsc.Id, _dsc.UserName);

            //creating managers
            var managerStore   = new UserStore <Manager>(new ApplicationDbContext());
            var managerManager = new UserManager <Manager>(managerStore);

            //Manager 1
            string _odinPmUserName1 = "*****@*****.**";
            var    pmUser1          = managerManager.FindByName(_odinPmUserName1);

            if (pmUser1 == null)
            {
                var newPm = new Manager()
                {
                    UserName    = _odinPmUserName1,
                    FirstName   = "Odin",
                    LastName    = "Pm",
                    Email       = _odinPmUserName1,
                    PhoneNumber = "2166824239"
                };
                managerManager.Create(newPm, "OdinOdin5$");
                managerManager.AddToRole(newPm.Id, UserRoles.ProgramManager);
                pmUser1 = managerManager.FindByName(_odinPmUserName1);
            }

            //Manager 2
            string _odinPmUserName2 = "*****@*****.**";
            var    pmUser2          = managerManager.FindByName(_odinPmUserName2);

            if (pmUser2 == null)
            {
                var newPm = new Manager()
                {
                    UserName    = _odinPmUserName2,
                    FirstName   = "Pratik",
                    LastName    = "Pm",
                    Email       = _odinPmUserName2,
                    PhoneNumber = "21689578545"
                };
                managerManager.Create(newPm, "OdinOdin5$");
                managerManager.AddToRole(newPm.Id, UserRoles.ProgramManager);
                pmUser2 = managerManager.FindByName(_odinPmUserName2);
            }

            //putting Orders in DB
            _context.Orders.AddRange(orders);
            _context.SaveChanges();

            //ManagerViewModels
            ManagerViewModel mngrvms1 = new ManagerViewModel();

            mngrvms1.FirstName   = pmUser1.FirstName;
            mngrvms1.Id          = pmUser1.Id;
            mngrvms1.LastName    = pmUser1.LastName;
            mngrvms1.phoneNumber = pmUser1.PhoneNumber;
            mngrvms1.Email       = pmUser1.Email;

            ManagerViewModel mngrvms2 = new ManagerViewModel();

            mngrvms2.FirstName   = pmUser2.FirstName;
            mngrvms2.Id          = pmUser2.Id;
            mngrvms2.LastName    = pmUser2.LastName;
            mngrvms2.phoneNumber = pmUser2.PhoneNumber;
            mngrvms2.Email       = pmUser2.Email;


            //Creating view models
            OrdersIndexViewModel ordersIndexViewModel1 = new OrdersIndexViewModel();

            ordersIndexViewModel1.Id             = orders[0].Id;
            ordersIndexViewModel1.ProgramManager = mngrvms1;

            OrdersIndexViewModel ordersIndexViewModel2 = new OrdersIndexViewModel();

            ordersIndexViewModel1.Id             = orders[1].Id;
            ordersIndexViewModel1.ProgramManager = mngrvms2;


            OrderIndexManagerViewModel orderIndexManagerViewModel = new OrderIndexManagerViewModel(Enumerable.Repeat(ordersIndexViewModel1, 1), Enumerable.Repeat(mngrvms1, 1));

            orderIndexManagerViewModel.Managers      = Enumerable.Repeat(mngrvms2, 1);
            orderIndexManagerViewModel.OrdersIndexVm = Enumerable.Repeat(ordersIndexViewModel2, 1);

            //act
            var OrdersIndexViewModelres = _controller.Index(pmUser1.Id) as ViewResult;

            //assert
            OrdersIndexViewModelres.Model.Equals(orderIndexManagerViewModel);
        }