Exemple #1
0
        public SingleResult <Order> AddShipment(int key, ODataActionParameters parameters)
        {
            var result = GetSingleResult(key);
            var order  = GetExpandedEntity(key, result, "OrderItems, OrderItems.Product, Shipments, Shipments.ShipmentItems");

            this.ProcessEntity(() =>
            {
                if (order.HasItemsToAddToShipment())
                {
                    var trackingNumber = parameters.GetValue <string, string>("TrackingNumber");

                    var shipment = _orderProcessingService.Value.AddShipment(order, trackingNumber, null);

                    if (shipment != null)
                    {
                        if (parameters.ContainsKey("SetAsShipped") && parameters.GetValue <string, bool>("SetAsShipped"))
                        {
                            _orderProcessingService.Value.Ship(shipment, true);
                        }
                    }
                }
                return(null);
            });

            return(result);
        }
Exemple #2
0
        public IHttpActionResult Login(ODataActionParameters parameters)
        {
            var email    = parameters.GetValue <string>(nameof(Common.Models.User.Email));
            var password = parameters.GetValue <string>(nameof(Common.Models.User.Password));

            var user = this.Entities.FirstOrDefault(u => u.Email == email && u.Password == password);

            if (user == null)
            {
                return(this.Unauthorized());
            }

            return(this.Ok(Mapper.Map <AuthenticateResponse>(user)));
        }
Exemple #3
0
        public SingleResult <Order> PaymentRefund(int key, ODataActionParameters parameters)
        {
            var result = GetSingleResult(key);
            var order  = GetExpandedEntity(key, result, null);

            this.ProcessEntity(() =>
            {
                bool online = parameters.GetValue <string, bool>("Online");

                if (online)
                {
                    var errors = _orderProcessingService.Value.Refund(order);

                    if (errors.Count > 0)
                    {
                        return(errors[0]);
                    }
                }
                else
                {
                    _orderProcessingService.Value.RefundOffline(order);
                }
                return(null);
            });

            return(result);
        }
Exemple #4
0
        public Order PaymentRefund(int key, ODataActionParameters parameters)
        {
            var entity = GetEntityByKeyNotNull(key);

            this.ProcessEntity(() =>
            {
                bool online = parameters.GetValue <string, bool>("Online");

                if (online)
                {
                    var errors = _orderProcessingService.Value.Refund(entity);

                    if (errors.Count > 0)
                    {
                        return(errors[0]);
                    }
                }
                else
                {
                    _orderProcessingService.Value.RefundOffline(entity);
                }
                return(null);
            });
            return(entity);
        }
Exemple #5
0
        public Order PaymentPaid(int key, ODataActionParameters parameters)
        {
            var entity = GetEntityByKeyNotNull(key);

            this.ProcessEntity(() =>
            {
                string paymentMethodName = parameters.GetValue <string, string>("PaymentMethodName");

                if (paymentMethodName != null)
                {
                    entity.PaymentMethodSystemName = paymentMethodName;
                    Service.UpdateOrder(entity);
                }

                _orderProcessingService.Value.MarkOrderAsPaid(entity);
                return(null);
            });
            return(entity);
        }
Exemple #6
0
        public SingleResult <Order> PaymentPaid(int key, ODataActionParameters parameters)
        {
            var result = GetSingleResult(key);
            var order  = GetExpandedEntity(key, result, null);

            this.ProcessEntity(() =>
            {
                string paymentMethodName = parameters.GetValue <string, string>("PaymentMethodName");

                if (paymentMethodName != null)
                {
                    order.PaymentMethodSystemName = paymentMethodName;
                    Service.UpdateOrder(order);
                }

                _orderProcessingService.Value.MarkOrderAsPaid(order);

                return(null);
            });

            return(result);
        }
        public IQueryable <ProductVariantAttribute> ManageAttributes(int key, ODataActionParameters parameters)
        {
            var entity = GetExpandedEntity <ICollection <ProductVariantAttribute> >(key, x => x.ProductVariantAttributes);
            var result = new List <ProductVariantAttributeValue>();

            this.ProcessEntity(() =>
            {
                bool synchronize = parameters.GetValue <string, bool>("Synchronize");
                var data         = (parameters["Attributes"] as IEnumerable <ManageAttributeType>).Where(x => x.Name.HasValue()).ToList();

                var allAttributes = _productAttributeService.Value.GetAllProductAttributes();

                foreach (var srcAttr in data)
                {
                    var productAttribute = allAttributes.FirstOrDefault(x => x.Name.IsCaseInsensitiveEqual(srcAttr.Name));

                    if (productAttribute == null)
                    {
                        productAttribute = new ProductAttribute()
                        {
                            Name = srcAttr.Name
                        };
                        _productAttributeService.Value.InsertProductAttribute(productAttribute);
                    }

                    var attribute = entity.ProductVariantAttributes.FirstOrDefault(x => x.ProductAttribute.Name.IsCaseInsensitiveEqual(srcAttr.Name));

                    if (attribute == null)
                    {
                        attribute = new ProductVariantAttribute()
                        {
                            ProductId              = entity.Id,
                            ProductAttributeId     = productAttribute.Id,
                            AttributeControlTypeId = srcAttr.ControlTypeId,
                            DisplayOrder           = entity.ProductVariantAttributes.OrderByDescending(x => x.DisplayOrder).Select(x => x.DisplayOrder).FirstOrDefault() + 1,
                            IsRequired             = srcAttr.IsRequired
                        };

                        entity.ProductVariantAttributes.Add(attribute);
                        Service.UpdateProduct(entity);
                    }
                    else if (synchronize)
                    {
                        if (srcAttr.Values.Count <= 0)
                        {
                            _productAttributeService.Value.DeleteProductVariantAttribute(attribute);
                        }
                        else
                        {
                            attribute.AttributeControlTypeId = srcAttr.ControlTypeId;
                            attribute.IsRequired             = srcAttr.IsRequired;

                            Service.UpdateProduct(entity);
                        }
                    }

                    int maxDisplayOrder = attribute.ProductVariantAttributeValues.OrderByDescending(x => x.DisplayOrder).Select(x => x.DisplayOrder).FirstOrDefault();

                    foreach (var srcVal in srcAttr.Values.Where(x => x.Name.HasValue()))
                    {
                        var value = attribute.ProductVariantAttributeValues.FirstOrDefault(x => x.Name.IsCaseInsensitiveEqual(srcVal.Name));

                        if (value == null)
                        {
                            value = new ProductVariantAttributeValue()
                            {
                                ProductVariantAttributeId = attribute.Id,
                                Name             = srcVal.Name,
                                Alias            = srcVal.Alias,
                                ColorSquaresRgb  = srcVal.ColorSquaresRgb,
                                PriceAdjustment  = srcVal.PriceAdjustment,
                                WeightAdjustment = srcVal.WeightAdjustment,
                                IsPreSelected    = srcVal.IsPreSelected,
                                DisplayOrder     = ++maxDisplayOrder
                            };

                            attribute.ProductVariantAttributeValues.Add(value);
                            Service.UpdateProduct(entity);
                        }
                        else if (synchronize)
                        {
                            value.Alias            = srcVal.Alias;
                            value.ColorSquaresRgb  = srcVal.ColorSquaresRgb;
                            value.PriceAdjustment  = srcVal.PriceAdjustment;
                            value.WeightAdjustment = srcVal.WeightAdjustment;
                            value.IsPreSelected    = srcVal.IsPreSelected;

                            Service.UpdateProduct(entity);
                        }
                    }

                    if (synchronize)
                    {
                        foreach (var dstVal in attribute.ProductVariantAttributeValues.ToList())
                        {
                            if (!srcAttr.Values.Any(x => x.Name.IsCaseInsensitiveEqual(dstVal.Name)))
                            {
                                _productAttributeService.Value.DeleteProductVariantAttributeValue(dstVal);
                            }
                        }
                    }
                }
                return(null);
            });

            return(entity.ProductVariantAttributes.AsQueryable());
        }