Exemplo n.º 1
0
        private void UpdateDistributor(DataAccess.Parcel parcel, DTO.User distributor)
        {
            CheckHelper.ArgumentNotNull(parcel, "parcel");

            if (distributor != null)
            {
                var distributorId = distributor.Id;
                CheckHelper.WithinCondition(distributorId > 0, "Distributor is new.");

                var persistentService = Container.Get <IPersistentService>();

                var user = persistentService.GetEntityById <User>(distributorId);
                CheckHelper.NotNull(user, "Distributor user does not exist.");
                CheckHelper.WithinCondition(
                    user.UserRoles.Any(r => r.Role.Name == DTO.Role.DISTRIBUTOR_ROLE_NAME && r.Active),
                    "User is not distributor.");

                parcel.DistributorId = user.Id;
                parcel.Distributor   = user;
            }
            else
            {
                parcel.DistributorId = null;
                parcel.Distributor   = null;
            }
        }
Exemplo n.º 2
0
        public static void Reset()
        {
            _parcel_1 = null;
            _parcel_2 = null;
            _parcel_3 = null;

            _parcels = null;
        }
Exemplo n.º 3
0
        private bool IsCurrentUserDistributorForParcel(DataAccess.Parcel parcel)
        {
            CheckHelper.ArgumentNotNull(parcel, "parcel");

            return
                (SecurityService.IsCurrentUserDistributor &&
                 parcel.DistributorId.HasValue &&
                 parcel.DistributorId == SecurityService.CurrentUser.Id);
        }
Exemplo n.º 4
0
        public DTO.Parcel CreateParcel(DataAccess.Parcel parcel, bool includeOnlyActive = false, Func <DataAccess.Order, bool> predicate = null)
        {
            CheckHelper.ArgumentNotNull(parcel, "parcel");
            CheckHelper.ArgumentWithinCondition(!parcel.IsNew(), "!parcel.IsNew()");

            return
                (_dtoCache.Get(
                     parcel,
                     p =>
            {
                var result =
                    new DTO.Parcel
                {
                    Id = p.Id,
                    Comments = p.Comments,
                    RublesPerDollar = p.RublesPerDollar,
                    PurchaserSpentOnDelivery = p.PurchaserSpentOnDelivery,
                    SentDate = p.SentDate,
                    ReceivedDate = p.ReceivedDate,
                    TrackingNumber = p.TrackingNumber,
                    CreateUserId = p.CreateUserId
                };

                CopyTrackableFields(result, p);

                return result;
            },
                     (pDto, p) =>
            {
                pDto.Distributor = p.Distributor != null ? CreateUser(p.Distributor) : null;

                predicate = predicate ?? (o => true);
                pDto.Orders =
                    p.Orders
                    .Where(o => o.Active || !includeOnlyActive)
                    .Where(predicate)
                    .OrderBy(o => o.Id)
                    .Select(o => CreateOrder(o, includeOnlyActive))
                    .ToArray();
            }));
        }
Exemplo n.º 5
0
        public void CreateParcel(DTO.Parcel createdParcel)
        {
            CheckHelper.ArgumentNotNull(createdParcel, "createdParcel");
            CheckHelper.ArgumentWithinCondition(createdParcel.IsNew(), "Parcel is not new.");
            Container.Get <IValidateService>().CheckIsValid(createdParcel);

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(SecurityService.IsCurrentUserPurchaser, "Only purchaser can create parcel.");

            var persistentService = Container.Get <IPersistentService>();

            var parcel =
                new DataAccess.Parcel
            {
                RublesPerDollar          = createdParcel.RublesPerDollar,
                PurchaserSpentOnDelivery = createdParcel.PurchaserSpentOnDelivery,
                TrackingNumber           = createdParcel.TrackingNumber,
                SentDate = createdParcel.SentDate,
                Comments = createdParcel.Comments
            };

            parcel.UpdateTrackFields(Container);
            UpdateDistributor(parcel, createdParcel.Distributor);

            persistentService.Add(parcel);

            persistentService.SaveChanges();

            createdParcel.Id         = parcel.Id;
            createdParcel.CreateDate = parcel.CreateDate;
            createdParcel.CreateUser = parcel.CreatedBy.GetFullName();
            createdParcel.ChangeDate = parcel.ChangeDate;
            createdParcel.ChangeUser = parcel.ChangedBy.GetFullName();

            createdParcel.ReceivedDate = null;
        }