Пример #1
0
        public DTO.OrderItem[] GetOrderItems(DTO.Order order)
        {
            CheckHelper.ArgumentNotNull(order, "order");
            CheckHelper.ArgumentWithinCondition(!order.IsNew(), "Order is new.");

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(
                SecurityService.IsCurrentUserSeller ||
                SecurityService.IsCurrentUserPurchaser ||
                SecurityService.IsCurrentUserDistributor,
                "Only seller, purchaser and distributor can get all order items.");

            var orderId = order.Id;

            var currentOrder =
                Container
                .Get <IPersistentService>()
                .GetEntityById <DataAccess.Order>(orderId);

            CheckHelper.NotNull(currentOrder, "Order does not exist.");

            var currentParcel = currentOrder.Parcel;

            var currentUserId = SecurityService.CurrentUser.Id;

            CheckHelper.WithinCondition(
                SecurityService.IsCurrentUserPurchaser ||
                (SecurityService.IsCurrentUserDistributor && currentParcel != null && currentParcel.Distributor != null && currentParcel.DistributorId == currentUserId) ||
                (SecurityService.IsCurrentUserSeller && currentOrder.CreateUserId == currentUserId),
                "Current user is either distributor and order is not included in parcel assigned to him or seller and order is not created by him.");

            var dtoService = Container.Get <IDtoService>();

            Func <DataAccess.Order, bool> predicate = null;

            if (SecurityService.IsCurrentUserSeller &&
                !SecurityService.IsCurrentUserPurchaser &&
                !(SecurityService.IsCurrentUserDistributor && currentParcel != null && currentParcel.Distributor != null && currentParcel.DistributorId == currentUserId))
            {
                predicate = o => o.CreateUserId == currentUserId;
            }

            return
                (Container
                 .Get <IPersistentService>()
                 .GetEntitySet <OrderItem>()
                 .Where(oi => oi.OrderId == orderId)
                 .OrderBy(oi => oi.Id)
                 .AsEnumerable()
                 .Select(oi => dtoService.CreateOrderItem(oi, false, predicate))
                 .ToArray());
        }
Пример #2
0
        public void CreateOrder(DTO.Order createdOrder)
        {
            CheckHelper.ArgumentNotNull(createdOrder, "createdOrder");
            CheckHelper.ArgumentWithinCondition(createdOrder.IsNew(), "Order is not new.");
            Container.Get <IValidateService>().CheckIsValid(createdOrder);

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can create order.");

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

            var order =
                new DataAccess.Order
            {
                OrderDate           = createdOrder.OrderDate,
                CustomerFirstName   = createdOrder.CustomerFirstName,
                CustomerLastName    = createdOrder.CustomerLastName,
                CustomerAddress     = createdOrder.CustomerAddress,
                CustomerCity        = createdOrder.CustomerCity,
                CustomerCountry     = createdOrder.CustomerCountry,
                CustomerPostalCode  = createdOrder.CustomerPostalCode,
                CustomerPhoneNumber = createdOrder.CustomerPhoneNumber,
                CustomerEmail       = createdOrder.CustomerEmail,
                Active          = createdOrder.Active,
                Comments        = createdOrder.Comments,
                RublesPerDollar = createdOrder.RublesPerDollar,
                CustomerPrepaid = createdOrder.CustomerPrepaid,
                CustomerPaid    = createdOrder.CustomerPaid
            };

            order.UpdateTrackFields(Container);

            persistentService.Add(order);
            persistentService.SaveChanges();

            createdOrder.Id         = order.Id;
            createdOrder.CreateDate = order.CreateDate;
            createdOrder.CreateUser = order.CreatedBy.GetFullName();
            createdOrder.ChangeDate = order.ChangeDate;
            createdOrder.ChangeUser = order.ChangedBy.GetFullName();

            createdOrder.Parcel = null;
            createdOrder.DistributorSpentOnDelivery = 0m;
            createdOrder.TrackingNumber             = null;
        }
Пример #3
0
        public void UpdateOrder(DTO.Order updatedOrder)
        {
            CheckHelper.ArgumentNotNull(updatedOrder, "updatedOrder");
            CheckHelper.ArgumentWithinCondition(!updatedOrder.IsNew(), "Order is new.");
            Container.Get <IValidateService>().CheckIsValid(updatedOrder);

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(
                SecurityService.IsCurrentUserSeller ||
                SecurityService.IsCurrentUserPurchaser ||
                SecurityService.IsCurrentUserDistributor,
                "Only seller, purchaser and distributor can change order.");

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

            var order = persistentService.GetEntityById <DataAccess.Order>(updatedOrder.Id);

            CheckHelper.NotNull(order, "Order does not exist.");
            CheckHelper.WithinCondition(
                SecurityService.IsCurrentUserPurchaser ||
                IsCurrentUserDistributorForOrder(order) ||
                IsCurrentUserSellerForOrder(order),
                "Only seller, purchaser and distributor can change order.");

            if (IsCurrentUserDistributorForOrder(order))
            {
                order.DistributorSpentOnDelivery = updatedOrder.DistributorSpentOnDelivery;
                order.TrackingNumber             = updatedOrder.TrackingNumber;
            }
            else
            {
                updatedOrder.DistributorSpentOnDelivery = order.DistributorSpentOnDelivery;
                updatedOrder.TrackingNumber             = order.TrackingNumber;
            }

            if (IsCurrentUserSellerForOrder(order))
            {
                order.OrderDate           = updatedOrder.OrderDate;
                order.CustomerFirstName   = updatedOrder.CustomerFirstName;
                order.CustomerLastName    = updatedOrder.CustomerLastName;
                order.CustomerAddress     = updatedOrder.CustomerAddress;
                order.CustomerCity        = updatedOrder.CustomerCity;
                order.CustomerCountry     = updatedOrder.CustomerCountry;
                order.CustomerPostalCode  = updatedOrder.CustomerPostalCode;
                order.CustomerPhoneNumber = updatedOrder.CustomerPhoneNumber;
                order.CustomerEmail       = updatedOrder.CustomerEmail;
                order.Active          = updatedOrder.Active;
                order.Comments        = updatedOrder.Comments;
                order.RublesPerDollar = updatedOrder.RublesPerDollar;
                order.CustomerPrepaid = updatedOrder.CustomerPrepaid;
                order.CustomerPaid    = updatedOrder.CustomerPaid;
            }
            else
            {
                updatedOrder.OrderDate           = order.OrderDate;
                updatedOrder.CustomerFirstName   = order.CustomerFirstName;
                updatedOrder.CustomerLastName    = order.CustomerLastName;
                updatedOrder.CustomerAddress     = order.CustomerAddress;
                updatedOrder.CustomerCity        = order.CustomerCity;
                updatedOrder.CustomerCountry     = order.CustomerCountry;
                updatedOrder.CustomerPostalCode  = order.CustomerPostalCode;
                updatedOrder.CustomerPhoneNumber = order.CustomerPhoneNumber;
                updatedOrder.CustomerEmail       = order.CustomerEmail;
                updatedOrder.Active          = order.Active;
                updatedOrder.Comments        = order.Comments;
                updatedOrder.RublesPerDollar = order.RublesPerDollar;
                updatedOrder.CustomerPrepaid = order.CustomerPrepaid;
                updatedOrder.CustomerPaid    = order.CustomerPaid;
            }

            if (SecurityService.IsCurrentUserPurchaser)
            {
                UpdateParcel(order, updatedOrder.Parcel);
            }
            else
            {
                updatedOrder.Parcel =
                    order.Parcel == null
                        ? null
                        : Container.Get <IDtoService>().CreateParcel(order.Parcel);
            }

            order.UpdateTrackFields(Container);

            persistentService.SaveChanges();
        }