Пример #1
0
        public virtual async Task <IHttpActionResult> PostCmsImport(Guid id)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                _logger.Error(InvalidMediaTypeMessage, Request.CreateResponseException(InvalidMediaTypeMessage, HttpStatusCode.UnsupportedMediaType));
                throw Request.CreateResponseException(InvalidMediaTypeMessage, HttpStatusCode.UnsupportedMediaType);
            }

            var file = await Request.GetUploadedFile(UploadPaths.IntegrationDataPath);

            var destinationRoot = _permanentLinkMapper.Find(id);

            if (destinationRoot == null)
            {
                return(Ok(id));
            }

            var importerOptions = ImportOptions.DefaultOptions;

            importerOptions.KeepIdentity                = true;
            importerOptions.ValidateDestination         = true;
            importerOptions.EnsureContentNameUniqueness = true;
            importerOptions.IsTest = false;
            var importer = _dataImporterAccessor();

            PrincipalInfo.RecreatePrincipalForThreading();
            var state = new ImporterState
            {
                Destination = destinationRoot.ContentReference,
                Importer    = importer,
                Options     = importerOptions,
                Stream      = new FileStream(file.LocalFileName, FileMode.Open)
            };

            var message = await ImportFileThread(state);

            if (string.IsNullOrEmpty(message))
            {
                return(Ok(id));
            }
            else
            {
                throw Request.CreateResponseException(message, HttpStatusCode.InternalServerError);
            }
        }
Пример #2
0
        public virtual IHttpActionResult GetContact(Guid contactId)
        {
            Logger.LogGet("GetContact", Request, new[] { contactId.ToString() });

            Contact contact;

            try
            {
                contact = CustomerContext.Current.GetContactById(contactId).ConvertToContact();
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }

            return(Ok(contact));
        }
Пример #3
0
        public virtual IHttpActionResult GetCart(Guid customerId, string name)
        {
            Logger.LogGet("GetCart", Request, new [] { customerId.ToString(), name });
            if (string.IsNullOrEmpty(name))
            {
                name = _defaultName;
            }

            try
            {
                var cart = _orderRepository.Load <Cart>(customerId, name).FirstOrDefault()
                           ?? _orderRepository.Create <Cart>(customerId, name);
                return(Ok(cart));
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }
        }
Пример #4
0
        public virtual IHttpActionResult GetOrder(int orderGroupId)
        {
            Logger.LogGet("GetOrders", Request, new[] { orderGroupId.ToString() });

            try
            {
                var order = _orderRepository.Load <PurchaseOrder>(orderGroupId);
                if (order == null)
                {
                    return(NotFound());
                }

                return(Ok(order.ConvertToPurchaseOrder()));
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }
        }