Exemple #1
0
        public void DeletingCategoryShouldDeleteProductMapping()
        {
            //build
            var category = new CategoryBuilder().Build();

            _documentService.AddDocument(category);
            var product = new ProductBuilder().Build();

            _documentService.AddDocument(product);

            //test
            _productService.AddCategory(product, category.Id);
            product.Categories.Count.Should().Be(1);
            _documentService.DeleteDocument(category);
            product.Categories.Count.Should().Be(0);
        }
        // POST api/<controller>
        public async Task <IHttpActionResult> Post()
        {
            //TODO verify for admin role
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var provider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(provider);

            var file = provider.Contents.FirstOrDefault();

            if (file == null)
            {
                return(BadRequest("File is missing"));
            }

            var filename      = file.Headers.ContentDisposition.FileName.Trim('\"');
            var fileExtension = Path.GetExtension(filename);

            if (string.IsNullOrEmpty(filename) || string.IsNullOrEmpty(fileExtension))
            {
                return(BadRequest("File name is invalid"));
            }

            using (var stream = await file.ReadAsStreamAsync())
            {
                var documentId = await _documentService.AddDocument(stream, filename);

                return(CreatedAtRoute("DefaultApi", new { id = documentId }, new { id = documentId }));
            }
        }
Exemple #3
0
        public string ImportPictures(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            var pictureData = dataReader.GetPictureData();

            var mediaCategory = _documentService.GetDocumentByUrl <MediaCategory>(NopProductImages);

            if (mediaCategory == null)
            {
                mediaCategory = new MediaCategory
                {
                    Name           = "Nop Product Images",
                    UrlSegment     = NopProductImages,
                    IsGallery      = false,
                    HideInAdminNav = false
                };
                _documentService.AddDocument(mediaCategory);
            }

            foreach (var data in pictureData)
            {
                using (var fileData = data.GetData())
                {
                    var memoryStream = new MemoryStream();
                    fileData.CopyTo(memoryStream);
                    memoryStream.Position = 0;

                    var mediaFile = _fileService.AddFile(memoryStream, data.FileName, data.ContentType, memoryStream.Length,
                                                         mediaCategory);
                    nopImportContext.AddEntry(data.Id, mediaFile);
                }
            }

            return(string.Format("{0} pictures imported", pictureData.Count));
        }
 public virtual ActionResult Add(MediaCategory doc)
 {
     _documentService.AddDocument(doc);
     _fileAdminService.CreateFolder(doc);
     TempData.SuccessMessages().Add(string.Format("{0} successfully added", doc.Name));
     return(RedirectToAction("Show", new { id = doc.Id }));
 }
Exemple #5
0
        public void ApproveDocument(string userName, string documentId, string manCo, string docType, string subDocType)
        {
            var document = _documentService.GetDocument(documentId);

            if (document == null)
            {
                _documentService.AddDocument(documentId, docType, subDocType, manCo, null);
                document = _documentService.GetDocument(documentId);
            }

            if (document.Approval != null)
            {
                throw new DocumentAlreadyApprovedException("Document is already approved");
            }

            if (document.Rejection != null)
            {
                throw new DocumentAlreadyRejectedException("Document is already rejected");
            }

            var approval = new Approval
            {
                ApprovedBy   = userName,
                ApprovedDate = DateTime.Now,
                DocumentId   = document.Id
            };

            _approvalRepository.Create(approval);
        }
Exemple #6
0
        public async Task <ActionResult <SingleResponse <Document> > > AddPdf([FromForm] PdfDocument pdf)
        {
            if (pdf == null)
            {
                return(BadRequest("Please provide PDF"));
            }

            var response = new SingleResponse <Document>();

            if (!ModelState.IsValid)
            {
                response.ErrorMessage = _modelStateErrorHandler.GetValues(ModelState);
                return(new ObjectResult(response)
                {
                    StatusCode = (int)HttpStatusCode.BadRequest
                });
            }

            var location = await _service.AddDocument(pdf.File);

            response.Model = await _service.AddDocumentRecord(pdf.File.FileName, location, pdf.File.Length);

            return(new ObjectResult(response)
            {
                StatusCode = (int)HttpStatusCode.Created
            });
        }
        public void MediaCategoryController_AddPost_ShouldCallSaveDocument()
        {
            var mediaCategory = new MediaCategory();

            _mediaCategoryController.Add(mediaCategory);

            A.CallTo(() => _documentService.AddDocument(mediaCategory)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void LayoutController_AddPost_ShouldCallSaveDocument()
        {
            var layout = new Layout();

            _layoutController.Add(layout);

            A.CallTo(() => _documentService.AddDocument(layout)).MustHaveHappened(Repeated.Exactly.Once);
        }
Exemple #9
0
        public virtual ActionResult UploadDocument(int AccessCode)
        {
            DocumentDTO uploadedFile = GetSingleUploadedFile();

            ServiceResponse serviceResponse = _documentService.AddDocument(uploadedFile.DocumentName, uploadedFile.FileContents, uploadedFile.ContentType, AccessCode);


            return(Json(serviceResponse));
        }
        private MediaCategory CreateFileUploadMediaCategory()
        {
            var mediaCategory = new MediaCategory {
                UrlSegment = "file-uploads", Name = "File Uploads"
            };

            _documentService.AddDocument(mediaCategory);
            return(mediaCategory);
        }
Exemple #11
0
        public void Execute(OnAddingArgs <Product> args)
        {
            var product = args.Item;

            if (!product.Variants.Any())
            {
                var productVariant = new ProductVariant
                {
                    Name           = product.Name,
                    TrackingPolicy = TrackingPolicy.DontTrack,
                };
                product.Variants.Add(productVariant);
                productVariant.Product = product;
                _session.Transact(s => s.Save(productVariant));
            }

            var mediaCategory = _documentService.GetDocumentByUrl <MediaCategory>("product-galleries");

            if (mediaCategory == null)
            {
                mediaCategory = new MediaCategory
                {
                    Name           = "Product Galleries",
                    UrlSegment     = "product-galleries",
                    IsGallery      = true,
                    HideInAdminNav = true
                };
                _documentService.AddDocument(mediaCategory);
            }
            var productGallery = new MediaCategory
            {
                Name           = product.Name,
                UrlSegment     = "product-galleries/" + product.UrlSegment,
                IsGallery      = true,
                Parent         = mediaCategory,
                HideInAdminNav = true
            };

            product.Gallery = productGallery;

            _documentService.AddDocument(productGallery);
        }
        public void WebpageController_AddPost_ShouldCallSaveDocument()
        {
            var webpage = new TextPage {
            };

            A.CallTo(() => _urlValidationService.UrlIsValidForWebpage(null, null)).Returns(true);

            _webpageController.Add(webpage);

            A.CallTo(() => _documentService.AddDocument <Webpage>(webpage)).MustHaveHappened();
        }
Exemple #13
0
 public virtual ActionResult Add([IoCModelBinder(typeof(AddWebpageModelBinder))] Webpage doc)
 {
     if (!_urlValidationService.UrlIsValidForWebpage(doc.UrlSegment, null))
     {
         _webpageBaseViewDataService.SetAddPageViewData(ViewData, doc.Parent as Webpage);
         return(View(doc));
     }
     _documentService.AddDocument(doc);
     TempData.SuccessMessages().Add(string.Format("{0} successfully added", doc.Name));
     return(RedirectToAction("Edit", new { id = doc.Id }));
 }
Exemple #14
0
        private void SaveDocumentToDatabase(ExtractedDocument extractedDocument, int docTypeId, int subDocTypeId, int manCoId, int gridRunId)
        {
            _documentService.AddDocument(
                extractedDocument.DocumentId,
                docTypeId,
                subDocTypeId,
                manCoId,
                gridRunId,
                extractedDocument.MailPrintFlag);

            NexdoxMessaging.SendMessage(string.Format("Document {0} saved to database", extractedDocument.DocumentId), true, this);
        }
        public IActionResult Add(AddDocumentDto addDocumentDto)
        {
            if (addDocumentDto.AddDocument == null)
            {
                return(RedirectToAction("Documents"));
            }


            bool result = _documentService.AddDocument(addDocumentDto);

            if (result)
            {
                TempData["DocumentStatus"] = "DocumentAdded";
                return(RedirectToAction("Documents"));
            }


            TempData["DocumentStatus"] = "DocumentNotAdded";
            return(RedirectToAction("Documents"));
        }
Exemple #16
0
        private void CreateDocumentReceipt(int?documentTypeId, List <ProductOperation> productOperations)
        {
            if (documentTypeId == null || documentTypeId == 0)
            {
                throw new Exception("Ошибка при инициализации данных в базе: не удалось получить ID типа документа");
            }

            //Создать документ
            var document = _documentService.AddDocument(new Document {
                DocumentDate = DateTime.Now, DocumentTypeId = (int)documentTypeId, IsOpen = true
            });

            if (document.Id == 0)
            {
                throw new Exception("Ошибка при инициализации данных в базе: не удалось создать документ");
            }

            //занести в БД операции, закрыть документ
            _documentService.PostingDocument(productOperations, document);
        }
Exemple #17
0
        public bool SaveEmployee(EmployeeBaseData employeeData)
        {
            if (employeeData.Employee.EmployeeId > 0)
            {
                employeeRepository.Update(employeeData.Employee);
            }
            else
            {
                employeeRepository.Add(employeeData.Employee);
            }
            if (employeeData.EmployeePhoto != null)
            {
                documentService.AddDocument(employeeData.EmployeePhoto, employeeData.Employee.EmployeeId, DocumentType.EmployeePhoto);
            }
            employeeRepository.SaveChanges();

            //SaveEmployeeSupervisors(employeeData);

            return(true);
        }
        public ActionResult AddDocument(int sortOrder, [FromForm] IFormFile document)
        {
            if (document == null)
            {
                return(BadRequest("Document to upload is required."));
            }

            //Reviewer : In future I would check the content type and move this out as a fluent validation.
            if (!Path.GetExtension(document.FileName).Equals(".pdf", StringComparison.OrdinalIgnoreCase))
            {
                return(BadRequest("Invalid file type"));
            }

            documentService.AddDocument(new DocumentModel
            {
                SortOrder = sortOrder,
                FileSize  = document.Length.ToString(),
                Name      = document.FileName
            });

            return(Ok());
        }
Exemple #19
0
        public CheckOut CheckOutDocument(string userName, string documentId, string manCo, string docType, string subDocType)
        {
            CheckOut checkOut = null;

            var document = _documentService.GetDocument(documentId);

            if (document == null)
            {
                _documentService.AddDocument(documentId, docType, subDocType, manCo, null);
                document = _documentService.GetDocument(documentId);
            }

            checkOut = new CheckOut
            {
                CheckOutBy   = userName,
                CheckOutDate = DateTime.Now,
                DocumentId   = document.Id
            };

            _checkOutRepository.Create(checkOut);
            return(checkOut);
        }
        public void CanHexOperatableTest()
        {
            var canExecuteCatched = false;
            var enumDoc           = _mainDocService.CreateNewEnumerableDocument();
            var hexDoc            = enumDoc.CreateNewDocument();

            enumDoc.AddDocument(hexDoc);
            enumDoc.SelectedDocument = hexDoc;
            var context = _hexService.CreateNewHexDataContext(null);

            hexDoc.SetInstance(context, SingularityForensic.Contracts.Hex.Constants.Tag_HexDataContext);

            ServiceProvider.GetInstance <HexUIServiceImpl>().FindHexValueCommand.CanExecuteChanged += (sender, e) => {
                canExecuteCatched = true;
            };


            _mainDocService.AddDocument(enumDoc);
            Assert.IsTrue(ServiceProvider.GetInstance <HexUIServiceImpl>().CanHexOperatable);

            Assert.IsTrue(canExecuteCatched);
        }
Exemple #21
0
 /// <summary>
 /// Создает документ реализации
 /// </summary>
 private void CreateSaleDocument()
 {
     _document = _documentService.AddDocument(new Document
     {
         IsOpen         = true,
         DocumentTypeId = (int)DocumentTypeEn.Sale,
         DocumentDate   = DateTime.Now //пока текущая дата
     });
     if (_document == null || _document.Id == 0)
     {
         throw new Exception("Не удалось создать документ реализации");
     }
     CurrentDocument = new DocumentView
     {
         IsOpen         = false,
         DocumentTypeId = _document.DocumentTypeId,
         DocumentId     = _document.Id,
         PositionCount  = 0,
         TypeName       = "Реализация (Открыт)",
         Amount         = 0
     };
     UpdateNomenclatureList();
     UpdateDataDocInPanel();
 }
 public IActionResult AddDocument(Document document)
 {
     //UserService service = new UserService();
     return(Ok(_documentService.AddDocument(document)));
 }
Exemple #23
0
        public PageModel Setup(MediaModel mediaModel)
        {
            var pageModel = new PageModel();

            var productSearch = new ProductSearch
            {
                Name               = "Categories",
                UrlSegment         = "categories",
                RevealInNavigation = true
            };
            var categoryContainer = new ProductContainer
            {
                Name               = "Products",
                UrlSegment         = "products",
                RevealInNavigation = false
            };

            _documentService.AddDocument(productSearch);
            _documentService.PublishNow(productSearch);
            _documentService.AddDocument(categoryContainer);
            _documentService.PublishNow(categoryContainer);
            pageModel.ProductSearch = productSearch;

            var now        = DateTime.UtcNow;
            var yourBasket = new Cart
            {
                Name               = "Your Basket",
                UrlSegment         = "basket",
                RevealInNavigation = false,
                PublishOn          = now
            };

            _documentService.AddDocument(yourBasket);
            var enterOrderEmail = new EnterOrderEmail
            {
                Name               = "Enter Order Email",
                UrlSegment         = "enter-order-email",
                RevealInNavigation = false,
                Parent             = yourBasket,
                DisplayOrder       = 0,
                PublishOn          = now,
            };

            _documentService.AddDocument(enterOrderEmail);
            var setPaymentDetails = new PaymentDetails
            {
                Name               = "Set Payment Details",
                UrlSegment         = "set-payment-details",
                RevealInNavigation = false,
                Parent             = yourBasket,
                DisplayOrder       = 1,
                PublishOn          = now,
            };

            _documentService.AddDocument(setPaymentDetails);
            var setDeliveryDetails = new SetShippingDetails
            {
                Name               = "Set Shipping Details",
                UrlSegment         = "set-shipping-details",
                RevealInNavigation = false,
                Parent             = yourBasket,
                DisplayOrder       = 2,
                PublishOn          = now,
            };

            _documentService.AddDocument(setDeliveryDetails);
            var orderPlaced = new OrderPlaced
            {
                Name               = "Order Placed",
                UrlSegment         = "order-placed",
                RevealInNavigation = false,
                Parent             = yourBasket,
                DisplayOrder       = 3,
                PublishOn          = now,
            };

            _documentService.AddDocument(orderPlaced);

            // User Account
            var userAccount = new SitemapPlaceholder
            {
                Name               = "User Account",
                UrlSegment         = "user-account",
                RevealInNavigation = false,
                PublishOn          = now
            };

            _documentService.AddDocument(userAccount);

            var userAccountInfo = new UserAccountInfo
            {
                Name               = "Account Details",
                UrlSegment         = "user-account-details",
                RevealInNavigation = false,
                PublishOn          = now,
                Parent             = userAccount
            };

            _documentService.AddDocument(userAccountInfo);

            var userAccountPassword = new UserAccountChangePassword
            {
                Name               = "Change Password",
                UrlSegment         = "user-account-change-password",
                RevealInNavigation = false,
                PublishOn          = now,
                Parent             = userAccount
            };

            _documentService.AddDocument(userAccountPassword);

            var userAccountAddresses = new UserAccountAddresses
            {
                Name               = "Account Addresses",
                UrlSegment         = "user-account-addresses",
                RevealInNavigation = false,
                PublishOn          = now,
                Parent             = userAccount
            };

            _documentService.AddDocument(userAccountAddresses);

            var editAddress = new UserAccountEditAddress
            {
                Name               = "Edit Address",
                UrlSegment         = userAccountAddresses.UrlSegment + "/edit-address",
                RevealInNavigation = false,
                PublishOn          = now,
                Parent             = userAccountAddresses
            };

            _documentService.AddDocument(editAddress);

            var userAccountOrders = new UserAccountOrders
            {
                Name               = "Orders",
                UrlSegment         = "user-account-orders",
                RevealInNavigation = false,
                PublishOn          = now,
                Parent             = userAccount
            };

            _documentService.AddDocument(userAccountOrders);

            var userOrder = new UserOrder
            {
                Name               = "View Order",
                UrlSegment         = "user-account-orders/order",
                RevealInNavigation = false,
                PublishOn          = now,
                Parent             = userAccountOrders
            };

            _documentService.AddDocument(userOrder);

            var userAccountReviews = new UserAccountReviews
            {
                Name               = "Reviews",
                UrlSegment         = "user-account-reviews",
                RevealInNavigation = false,
                PublishOn          = now,
                Parent             = userAccount
            };

            _documentService.AddDocument(userAccountReviews);

            var userAccountRewards = new UserAccountRewardPoints
            {
                Name               = "Reward Points",
                UrlSegment         = "user-account-reward-points",
                RevealInNavigation = false,
                PublishOn          = now,
                Parent             = userAccount
            };

            _documentService.AddDocument(userAccountRewards);

            // End User Account


            //Added to cart
            var addedToCart = new ProductAddedToCart
            {
                Name               = "Added to Basket",
                UrlSegment         = "add-to-basket",
                RevealInNavigation = false,
                PublishOn          = now
            };

            _documentService.AddDocument(addedToCart);
            pageModel.ProductAddedToCart = addedToCart;

            var wishlist = new ShowWishlist
            {
                Name               = "Wishlist",
                UrlSegment         = "wishlist",
                RevealInNavigation = true,
                PublishOn          = now
            };

            _documentService.AddDocument(wishlist);

            var newIn = new NewInProducts
            {
                Name               = "New In",
                UrlSegment         = "new-in",
                RevealInNavigation = true,
                PublishOn          = now
            };

            _documentService.AddDocument(newIn);

            var about = new TextPage()
            {
                Name               = "About us",
                UrlSegment         = "about-us",
                RevealInNavigation = true,
                PublishOn          = now,
                BodyContent        = EcommerceInstallInfo.AboutUsText
            };

            _documentService.AddDocument(about);

            //update core pages
            var homePage = _documentService.GetDocumentByUrl <TextPage>("home");

            if (homePage != null)
            {
                homePage.BodyContent = EcommerceInstallInfo.HomeCopy;
                var templates    = _pageTemplateAdminService.Search(new PageTemplateSearchQuery());
                var homeTemplate = templates.FirstOrDefault(x => x.Name == "Home Page");
                if (homeTemplate != null)
                {
                    homePage.PageTemplate = homeTemplate;
                }

                homePage.SubmitButtonText = "Sign up";
                _documentService.SaveDocument(homePage);
                pageModel.HomePage = homePage;
            }
            var page2 = _documentService.GetDocumentByUrl <TextPage>("page-2");

            if (page2 != null)//demopage in core not needed
            {
                _documentService.DeleteDocument(page2);
            }

            var contactus = _documentService.GetDocumentByUrl <TextPage>("contact-us");

            if (contactus != null)//demopage in core not needed
            {
                _documentService.DeleteDocument(contactus);
            }

            //Added to cart
            var contactUs = new ContactUs()
            {
                Name               = "Contact Us",
                UrlSegment         = "contact-us",
                RevealInNavigation = true,
                PublishOn          = now,
                Latitude           = 55.01021m,
                Longitude          = -1.44998m,
                Address            = EcommerceInstallInfo.Address,
                PinImage           = mediaModel.Logo.FileUrl,
                BodyContent        = "[form]",
                FormDesign         = EcommerceInstallInfo.ContactFormDesign
            };

            _documentService.AddDocument(contactUs);
            GetFormProperties(contactUs);

            var brandListing = new BrandListing
            {
                Name               = "Brands",
                UrlSegment         = "brands",
                RevealInNavigation = true,
                PublishOn          = now,
                BodyContent        = ""
            };

            _documentService.AddDocument(brandListing);

            return(pageModel);
        }
 public void GivenADocument_WhenDocumentIsAdded_ItIsSaved()
 {
     _documentService.AddDocument(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>());
     _documentRepository.Verify(s => s.Create(It.IsAny <Document>()), Times.Once());
 }
Exemple #25
0
        public JsonResult Document_Insert(Guid customerID, DocumentView document, HttpPostedFileBase file)
        {
            GeneralResponse response = new GeneralResponse();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("Document_Insert");
            if (!hasPermission)
            {
                response.ErrorMessages.Add("AccessDenied");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            #endregion

            string fileName = string.Empty;
            string path     = string.Empty;

            try
            {
                #region Upload file

                // Verify that the user selected a file
                if (file != null && file.ContentLength > 0)
                {
                    // extract the extention
                    var fileExtention = Path.GetExtension(file.FileName);
                    // create filename
                    //string fileName = response.ID + "." + fileExtention;
                    // fileName = Path.GetFileName(file.FileName);

                    // Create a unique file name
                    fileName = Guid.NewGuid() + "." + fileExtention;

                    // Gettin current Year and Month
                    PersianCalendar pc    = new PersianCalendar();
                    int             year  = pc.GetYear(DateTime.Now);
                    int             month = pc.GetMonth(DateTime.Now);

                    // Create File Path
                    path = Path.Combine(Server.MapPath("~/data/" + year + "/" + month), fileName);
                    // Create reqired directried if not exist
                    new FileInfo(path).Directory.Create();

                    // Uploading
                    using (var fs = new FileStream(path, FileMode.Create))
                    {
                        var buffer = new byte[file.InputStream.Length];
                        file.InputStream.Read(buffer, 0, buffer.Length);

                        fs.Write(buffer, 0, buffer.Length);
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                //response.success = false;
                response.ErrorMessages.Add("در آپلود کردن فایل خطایی به وجود آمده است.");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            #region Add Document

            AddDocumentRequest request = new AddDocumentRequest();

            request.CreateEmployeeID = GetEmployee().ID;
            request.CustomerID       = customerID;

            request.DocumentName = document.DocumentName;
            request.Photo        = path;
            request.Note         = document.Note;

            response = _documentService.AddDocument(request);

            #endregion

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
 public Task Handle(EnrollmentDone message, IMessageHandlerContext context)
 {
     log.Info($"Document Service , BclCode = {message.BclCode} - documents sent");
     svc.AddDocument(message.BclCode);
     return(Task.CompletedTask);
 }
Exemple #27
0
 public virtual ActionResult Add(Layout doc)
 {
     _documentService.AddDocument(doc);
     TempData.SuccessMessages().Add(string.Format("{0} successfully added", doc.Name));
     return(RedirectToAction("Edit", new { id = doc.Id }));
 }
Exemple #28
0
        public LayoutModel Setup(MediaModel mediaModel)
        {
            var layoutModel = new LayoutModel();
            //base layout
            var baseLayout = new Layout
            {
                Name        = "Base Ecommerce Layout",
                UrlSegment  = "_BaseEcommerceLayout",
                LayoutAreas = new List <LayoutArea>(),
            };

            _documentService.AddDocument(baseLayout);

            //ecommerce main layout
            var eCommerceLayout = new Layout
            {
                Name        = "Ecommerce Layout",
                UrlSegment  = "_EcommerceLayout",
                LayoutAreas = new List <LayoutArea>(),
                Parent      = baseLayout
            };
            var ecommerceLayoutArea = new List <LayoutArea>
            {
                new LayoutArea {
                    AreaName = "Header Left", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "Header Middle", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "Header Right", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "User Links", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "Navigation", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "Before Content", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "After Content", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "Footer Area 1", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "Footer Area 2", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "Footer Area 3", Layout = eCommerceLayout
                },
                new LayoutArea {
                    AreaName = "Footer Area 4", Layout = eCommerceLayout
                }
            };

            _documentService.AddDocument(eCommerceLayout);
            foreach (LayoutArea area in ecommerceLayoutArea)
            {
                _layoutAreaAdminService.SaveArea(area);
            }

            layoutModel.EcommerceLayout = eCommerceLayout;

            var homeLayout = new Layout
            {
                Name        = "Home Layout",
                UrlSegment  = "_HomeLayout",
                LayoutAreas = new List <LayoutArea>(),
                Parent      = eCommerceLayout
            };
            var homeLayoutAreas = new List <LayoutArea>
            {
                new LayoutArea {
                    AreaName = "Home After Content", Layout = homeLayout
                },
                new LayoutArea {
                    AreaName = "Teaser1", Layout = homeLayout
                },
                new LayoutArea {
                    AreaName = "Teaser2", Layout = homeLayout
                },
                new LayoutArea {
                    AreaName = "Teaser3", Layout = homeLayout
                },
                new LayoutArea {
                    AreaName = "Teaser4", Layout = homeLayout
                }
            };

            _documentService.AddDocument(homeLayout);
            foreach (LayoutArea area in homeLayoutAreas)
            {
                _layoutAreaAdminService.SaveArea(area);
            }
            layoutModel.HomeLayout = homeLayout;
            //checkout layout
            var checkoutLayout = new Layout
            {
                Name        = "Checkout Layout",
                UrlSegment  = "_CheckoutLayout",
                LayoutAreas = new List <LayoutArea>(),
                Parent      = eCommerceLayout
            };
            var checkoutLayoutAreas = new List <LayoutArea>
            {
                new LayoutArea {
                    AreaName = "Checkout Header Left", Layout = checkoutLayout
                },
                new LayoutArea {
                    AreaName = "Checkout Header Middle", Layout = checkoutLayout
                },
                new LayoutArea {
                    AreaName = "Checkout Header Right", Layout = checkoutLayout
                },
                new LayoutArea {
                    AreaName = "Checkout Footer Left", Layout = checkoutLayout
                },
                new LayoutArea {
                    AreaName = "Checkout Footer Right", Layout = checkoutLayout
                }
            };

            _documentService.AddDocument(checkoutLayout);

            foreach (LayoutArea area in checkoutLayoutAreas)
            {
                _layoutAreaAdminService.SaveArea(area);
            }
            layoutModel.CheckoutLayout = checkoutLayout;
            //product layout
            var productLayout = new Layout
            {
                Name        = "Product Layout",
                UrlSegment  = "_ProductLayout",
                LayoutAreas = new List <LayoutArea>(),
                Parent      = eCommerceLayout
            };
            var productLayoutAreas = new List <LayoutArea>
            {
                new LayoutArea {
                    AreaName = "Below Product Price", Layout = productLayout
                },
                new LayoutArea {
                    AreaName = "Below Add to cart", Layout = productLayout
                },
                new LayoutArea {
                    AreaName = "Below Product Information", Layout = productLayout
                },
                new LayoutArea {
                    AreaName = "Before Product Content", Layout = productLayout
                },
                new LayoutArea {
                    AreaName = "After Product Content", Layout = productLayout
                }
            };

            _documentService.AddDocument(productLayout);
            foreach (LayoutArea area in productLayoutAreas)
            {
                _layoutAreaAdminService.SaveArea(area);
            }
            layoutModel.ProductLayout = productLayout;
            //category/search layout
            var searchLayout = new Layout
            {
                Name        = "Search Layout",
                UrlSegment  = "_SearchLayout",
                LayoutAreas = new List <LayoutArea>(),
                Parent      = eCommerceLayout
            };
            var searchLayoutAreas = new List <LayoutArea>
            {
                new LayoutArea {
                    AreaName = "Before Filters", Layout = searchLayout
                },
                new LayoutArea {
                    AreaName = "After Filters", Layout = searchLayout
                }
            };

            _documentService.AddDocument(searchLayout);
            foreach (LayoutArea area in searchLayoutAreas)
            {
                _layoutAreaAdminService.SaveArea(area);
            }
            layoutModel.SearchLayout = searchLayout;

            var contentLayout = new Layout
            {
                Name        = "Content Layout",
                UrlSegment  = "_ContentLayout",
                LayoutAreas = new List <LayoutArea>(),
                Parent      = eCommerceLayout
            };

            _documentService.AddDocument(contentLayout);
            layoutModel.ContentLayout = contentLayout;

            // UserAccount
            var userAccountLayout = new Layout
            {
                Name        = "User Account Layout",
                UrlSegment  = "_UserAccountLayout",
                LayoutAreas = new List <LayoutArea>(),
                Parent      = eCommerceLayout
            };
            var userAccountAreas = new List <LayoutArea>
            {
                new LayoutArea {
                    AreaName = "Right Column", Layout = userAccountLayout
                }
            };

            _documentService.AddDocument(userAccountLayout);
            foreach (LayoutArea area in userAccountAreas)
            {
                _layoutAreaAdminService.SaveArea(area);
            }
            layoutModel.UserAccountLayout = userAccountLayout;

            //Page templates
            var homeTemplate = new PageTemplate
            {
                Name             = "Home Page",
                PageType         = typeof(TextPage).FullName,
                UrlGeneratorType = typeof(DefaultWebpageUrlGenerator).FullName,
                Layout           = homeLayout
            };

            _pageTemplateAdminService.Add(homeTemplate);

            SetPageDefaults(layoutModel);

            return(layoutModel);
        }
Exemple #29
0
        /// <summary>
        ///     Import from DTOs
        /// </summary>
        /// <param name="dataTransferObject"></param>
        public Product ImportProduct(ProductImportDataTransferObject dataTransferObject)
        {
            var uniquePage = _uniquePageService.GetUniquePage <ProductContainer>();
            var productGalleriesCategory = _documentService.GetDocumentByUrl <MediaCategory>("product-galleries");

            if (productGalleriesCategory == null)
            {
                productGalleriesCategory = new MediaCategory
                {
                    Name           = "Product Galleries",
                    UrlSegment     = "product-galleries",
                    IsGallery      = true,
                    HideInAdminNav = true
                };
                _documentService.AddDocument(productGalleriesCategory);
            }


            Product product =
                _session.Query <Product>()
                .SingleOrDefault(x => x.UrlSegment == dataTransferObject.UrlSegment) ??
                new Product();

            product.Parent          = uniquePage;
            product.UrlSegment      = dataTransferObject.UrlSegment;
            product.Name            = dataTransferObject.Name;
            product.BodyContent     = dataTransferObject.Description;
            product.MetaTitle       = dataTransferObject.SEOTitle;
            product.MetaDescription = dataTransferObject.SEODescription;
            product.MetaKeywords    = dataTransferObject.SEOKeywords;
            product.ProductAbstract = dataTransferObject.Abstract;
            product.PublishOn       = dataTransferObject.PublishDate;

            bool          isNew          = false;
            MediaCategory productGallery = product.Gallery ?? new MediaCategory();

            if (product.Id == 0)
            {
                isNew = true;
                product.DisplayOrder =
                    GetParentQuery(uniquePage).Any()
                        ? GetParentQuery(uniquePage)
                    .Select(Projections.Max <Webpage>(webpage => webpage.DisplayOrder))
                    .SingleOrDefault <int>()
                        : 0;
                productGallery.Name           = product.Name;
                productGallery.UrlSegment     = "product-galleries/" + product.UrlSegment;
                productGallery.IsGallery      = true;
                productGallery.Parent         = productGalleriesCategory;
                productGallery.HideInAdminNav = true;
                product.Gallery = productGallery;
            }

            SetBrand(dataTransferObject, product);

            SetCategories(dataTransferObject, product);

            SetOptions(dataTransferObject, product);

            ////Url History
            _importUrlHistoryService.ImportUrlHistory(dataTransferObject, product);

            ////Specifications
            _importSpecificationsService.ImportSpecifications(dataTransferObject, product);

            ////Variants
            _importProductVariantsService.ImportVariants(dataTransferObject, product);

            if (isNew)
            {
                _session.Transact(session => session.Save(product));
                _session.Transact(session => session.Save(productGallery));
            }
            else
            {
                _session.Transact(session => session.Update(product));
                _session.Transact(session => session.Update(productGallery));
            }

            _importProductImagesService.ImportProductImages(dataTransferObject.Images, product.Gallery);

            return(product);
        }