示例#1
0
        public async Task <IActionResult> PostClientCatalog([FromBody] ClientCatalogDto clientCatalog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ClientCatalog clientCatalogReversed = _mapper.Map <ClientCatalog>(clientCatalog);

            _context.ClientCatalogs.Add(clientCatalogReversed);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetClientCatalog", new { id = clientCatalogReversed.Id }, _mapper.Map <ClientCatalogDto>(clientCatalogReversed)));
        }
示例#2
0
        public void ClientCatalogProperlyMappedToClientCatalogDto()
        {
            ClientCatalogDto cDto1 = new ClientCatalogDto
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };
            ClientCatalog c1 = new ClientCatalog
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };

            ClientCatalogDto cDto2 = _mapper.Map <ClientCatalogDto>(c1);

            Assert.NotNull(cDto2);
            Assert.True(cDto1.Equals(cDto2));
            Assert.True(cDto1.Equals(cDto2, true));
        }
示例#3
0
        public void ClientCatalogDtoProperlyReversedToClientCatalog()
        {
            ClientCatalogDto cDto1 = new ClientCatalogDto
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };
            ClientCatalog c1 = new ClientCatalog
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };

            ClientCatalog c2 = _mapper.Map <ClientCatalog>(cDto1);

            Assert.NotNull(c2);
            Assert.True(c1.Equals(c2));
            Assert.True(c1.Equals(c2, true));
        }
示例#4
0
        public async Task <IActionResult> PutClientCatalog([FromRoute] int id, [FromBody] ClientCatalogDto clientCatalog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != clientCatalog.Id)
            {
                ModelState.AddModelError("Invalid Catalog ID", "The Catalog ID supplied in the query and the body of the request do not match.");
                return(BadRequest(ModelState));
            }

            ClientCatalog clientCatalogReversed = _mapper.Map <ClientCatalog>(clientCatalog);

            _context.Entry(clientCatalogReversed).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException xcp)
            {
                if (!ClientCatalogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    ModelState.AddModelError("Error", xcp.ToString());
                    return(BadRequest(ModelState));
                }
            }

            return(NoContent());
        }
        public static void Initialize(DocRepoContext context)
        {
            context.Database.EnsureCreated();

            if (context.DocumentUpdates.Any())
            {
                return;
            }


            var authors = new Author[]
            {
                new Author {
                    FirstName = "Jamie", LastName = "Smith", Alias = "JSMIT", Email = "*****@*****.**", AitName = "Jamie", IsFormerAuthor = false
                },
                new Author {
                    FirstName = "Ariel", LastName = "Taylor", Alias = "ATAYL", Email = "*****@*****.**", AitName = "Ariel", IsFormerAuthor = false
                },
                new Author {
                    FirstName = "Glen", LastName = "Williams", Alias = "GWILL", Email = "*****@*****.**", AitName = "Glen", IsFormerAuthor = false
                },
                new Author {
                    FirstName = "Shelby", LastName = "Clark", Alias = "SCLAR", Email = "*****@*****.**", AitName = "Shelby", IsFormerAuthor = true
                }
            };

            if (context.Authors.Count() < 4)
            {
                foreach (Author author in authors)
                {
                    context.Authors.Add(author);
                }

                context.SaveChanges();
            }

            var clientCatalogs = new ClientCatalog[]
            {
                new ClientCatalog {
                    Name = "Awesome Product"
                },
                new ClientCatalog {
                    Name = "Nice Product"
                },
                new ClientCatalog {
                    Name = "Old Product"
                },
                new ClientCatalog {
                    Name = "Mobile App"
                },
                new ClientCatalog {
                    Name = "CRM Solution"
                },
                new ClientCatalog {
                    Name = "Next Gen Portal"
                },
                new ClientCatalog {
                    Name = "Classic Portal"
                },
                new ClientCatalog {
                    Name = "Tools"
                },
                new ClientCatalog {
                    Name = "Framework"
                },
                new ClientCatalog {
                    Name = "Reporting"
                }
            };

            if (context.ClientCatalogs.Count() < 10)
            {
                foreach (ClientCatalog cat in clientCatalogs)
                {
                    context.ClientCatalogs.Add(cat);
                }

                context.SaveChanges();
            }



            if (context.DocumentTypes.Count() < 9)
            {
                var docTypes = new DocumentType[]
                {
                    new DocumentType {
                        FullName = "User Guide", ShortName = "UG", DocumentCategory = DocumentCategory.FunctionalDocumentation
                    },
                    new DocumentType {
                        FullName = "Configuration Guide", ShortName = "CG", DocumentCategory = DocumentCategory.FunctionalDocumentation
                    },
                    new DocumentType {
                        FullName = "Administrator Guide", ShortName = "AG", DocumentCategory = DocumentCategory.FunctionalDocumentation
                    },
                    new DocumentType {
                        FullName = "Reference Guide", ShortName = "RG", DocumentCategory = DocumentCategory.FunctionalDocumentation
                    },
                    new DocumentType {
                        FullName = "Knowledge Base", ShortName = "KB", DocumentCategory = DocumentCategory.FunctionalDocumentation
                    },
                    new DocumentType {
                        FullName = "Installation Guide", ShortName = "IG", DocumentCategory = DocumentCategory.TechnicalDocumentation
                    },
                    new DocumentType {
                        FullName = "System Requirements", ShortName = "SR", DocumentCategory = DocumentCategory.TechnicalDocumentation
                    },
                    new DocumentType {
                        FullName = "Technical Reference Guide", ShortName = "TRG", DocumentCategory = DocumentCategory.TechnicalDocumentation
                    },
                    new DocumentType {
                        FullName = "Release Notes", ShortName = "RN", DocumentCategory = DocumentCategory.ReleaseNotes
                    }
                };

                foreach (DocumentType docType in docTypes)
                {
                    context.DocumentTypes.Add(docType);
                }

                context.SaveChanges();
            }

            if (context.ProductVersions.Count() < 10)
            {
                var products = new Product[]
                {
                    new Product {
                        ShortName = "AP", FullName = "Awesome Product", Alias = "Product 1"
                    },
                    new Product {
                        ShortName = "NP", FullName = "Nice Product", Alias = "Product 2"
                    },
                    new Product {
                        ShortName = "OP", FullName = "Old Product", Alias = "Product 3"
                    },
                    new Product {
                        ShortName = "MP", FullName = "Mobile App", Alias = "Product 4"
                    },
                    new Product {
                        ShortName = "CRM", FullName = "CRM Solution", Alias = "Product 5"
                    },
                    new Product {
                        ShortName = "NGP", FullName = "Next Gen Portal", Alias = "Product 6"
                    },
                    new Product {
                        ShortName = "CP", FullName = "Classic Portal", Alias = "Product 7"
                    },
                    new Product {
                        ShortName = "R", FullName = "Reporting", Alias = "Product 8"
                    }
                };

                foreach (Product product in products)
                {
                    context.Products.Add(product);
                }

                List <KeyValuePair <string, DateTime> > versionsWithEndDate = new List <KeyValuePair <string, DateTime> >
                {
                    new KeyValuePair <string, DateTime>("V2017.1", DateTime.Parse("2018-01-01")),
                    new KeyValuePair <string, DateTime>("V2017.2", DateTime.Parse("2018-03-01")),
                    new KeyValuePair <string, DateTime>("V2017.3", DateTime.Parse("2018-05-01")),
                    new KeyValuePair <string, DateTime>("V2017.4", DateTime.Parse("2018-07-01")),
                    new KeyValuePair <string, DateTime>("V2017.5", DateTime.Parse("2018-09-01")),
                    new KeyValuePair <string, DateTime>("V2017.6", DateTime.Parse("2018-11-01")),
                    new KeyValuePair <string, DateTime>("V2018.1", DateTime.Parse("2019-01-01")),
                    new KeyValuePair <string, DateTime>("V2018.2", DateTime.Parse("2019-03-01")),
                    new KeyValuePair <string, DateTime>("V2018.3", DateTime.Parse("2019-05-01")),
                    new KeyValuePair <string, DateTime>("V2018.4", DateTime.Parse("2019-07-01")),
                    new KeyValuePair <string, DateTime>("V2018.5", DateTime.Parse("2019-09-01")),
                    new KeyValuePair <string, DateTime>("V2018.6", DateTime.Parse("2019-11-01"))
                };


                foreach (KeyValuePair <string, DateTime> version in versionsWithEndDate)
                {
                    var productVersions = Enumerable.Range(1, products.Count())
                                          .Select(i => new ProductVersion {
                        ProductId = i, Release = version.Key, EndOfSupport = version.Value
                    });
                    context.AddRange(productVersions);
                }

                context.SaveChanges();
            }

            List <Product>      productList      = context.Products.ToList();
            List <DocumentType> docTypeList      = context.DocumentTypes.ToList();
            ClientCatalog       catalogFramework = context.ClientCatalogs.SingleOrDefault(cat => cat.Name == "Framework");

            foreach (Product product in productList)
            {
                ClientCatalog catalog = context.ClientCatalogs.SingleOrDefault(cat => cat.Name == product.FullName);

                if (catalog == null)
                {
                    catalog = context.ClientCatalogs.SingleOrDefault(cat => cat.Name == "Tools");
                }

                List <ProductVersion> versions = context.ProductVersions.Where(v => v.ProductId == product.Id).ToList();

                foreach (ProductVersion version in versions)
                {
                    foreach (DocumentType docType in docTypeList)
                    {
                        string rootDir       = $"{product.FullName.Replace(" ", string.Empty)}/{docType.FullName.Replace(" ", string.Empty)}";
                        string printFileName = $"{product.FullName.Replace(" ", string.Empty)}_{docType.FullName.Replace(" ", string.Empty)}_{version.Release}";

                        Document document = new Document
                        {
                            Title           = $"{product.FullName} {docType.FullName}",
                            ProductVersion  = version,
                            DocumentType    = docType,
                            DocumentAuthors = new List <DocumentAuthor>
                            {
                                new DocumentAuthor {
                                    Author = authors[0]
                                },
                                new DocumentAuthor {
                                    Author = authors[1]
                                },
                                new DocumentAuthor {
                                    Author = authors[2]
                                }
                            },
                            HtmlLink = $"{rootDir}/HTML_{version.Release}/index.html",
                            PdfLink  = $"{rootDir}/PDF_{version.Release}/{printFileName}.pdf",
                            WordLink = $"{rootDir}/Word_{version.Release}/{printFileName}.docx",

                            IsFitForClients  = docType.ShortName != "CG" && docType.ShortName != "AG",
                            ShortDescription = $"The document contains the full {docType.FullName} for the {version.Release} of {product.FullName}",

                            Updates = Enumerable.Range(1, 10)
                                      .Select(j => new DocumentUpdate
                            {
                                IsPublished         = (j % 3 != 0),
                                LatestTopicsUpdated = $"This is version {j} of the document.",
                                Timestamp           = version.EndOfSupport.AddYears(-1).AddMonths(j - 1)
                            }).ToList(),

                            DocumentCatalogs = new List <DocumentCatalog>
                            {
                                new DocumentCatalog {
                                    Catalog = catalog
                                },
                                new DocumentCatalog {
                                    Catalog = catalogFramework
                                }
                            }
                        };

                        context.Add(document);
                    }
                }
            }

            context.SaveChanges();
        }