public ActionResult Index()
        {
            var repository = new ShipmentRepository();

            // users in Shipment Manager role can see all the shipments,
            // while others can see only its own shipments
            IEnumerable <Shipment> shipments;
            var organization = ClaimHelper.GetCurrentUserClaim(Fabrikam.ClaimTypes.Organization).Value;

            if (this.User.IsInRole(Fabrikam.Roles.ShipmentManager))
            {
                shipments = repository.GetShipmentsByOrganization(organization);
            }
            else
            {
                var userName = this.User.Identity.Name;
                shipments = repository.GetShipmentsByOrganizationAndUserName(organization, userName);
            }

            var model = new ShipmentListViewModel
            {
                Shipments = shipments
            };

            return(View(model));
        }
示例#2
0
        public ShipmentListViewModel GetShipmentsList()
        {
            using (ManBoxEntities ent = new ManBoxEntities())
            {
                ent.Configuration.LazyLoadingEnabled = true;

                var deliveries = (from sd in ent.SubscriptionDeliveries.Include(d => d.Subscription.User)
                                  where sd.Subscription.SubscriptionStateCV == CodeValues.SubscriptionState.Subscribed &&
                                  sd.DeliveryStateCV != CodeValues.DeliveryState.Dropped &&
                                  sd.DeliveryStateCV != CodeValues.DeliveryState.New &&
                                  sd.DeliveryStateCV != CodeValues.DeliveryState.Sent
                                  orderby sd.DeliveryDate
                                  select sd).ToList();

                var shipmentList = new ShipmentListViewModel()
                {
                    Deliveries = deliveries
                };

                return(shipmentList);
            }
        }