コード例 #1
0
        public IActionResult Post(CatalogueDetail catalogueDetail)
        {
            if (catalogueDetail == null)
            {
                return(BadRequest());
            }

            var checkDuplicate = _catalogueManagement.CheckExists(catalogueDetail);

            if (checkDuplicate == null)
            {
                var result = _catalogueManagement.AddCatalogue(catalogueDetail);

                if (result == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }

                return(Ok(result));
            }
            else
            {
                return(Conflict(checkDuplicate));
            }
        }
コード例 #2
0
        public string CheckExists(CatalogueDetail item)
        {
            var compare = item.CatalogueList.FirstOrDefault();

            var catalogue = GetCatalogues().FirstOrDefault(i => i.Type.ToLower() == item.Type.ToLower());

            if (catalogue == null)
            {
                return(null);
            }

            var exists = catalogue?.CatalogueList.FirstOrDefault(j => j.Name.ToLower() == compare.Name.ToLower());

            return(exists?.Id.ToString());
        }
コード例 #3
0
        public string AddCatalogue(CatalogueDetail item)
        {
            Guid catalogueId = Guid.NewGuid();

            var catalogue = GetCatalogues().FirstOrDefault(i => i.Type.ToLower() == item.Type.Trim().ToLower());

            var catalogues = item.CatalogueList
                             .Select(i => new Catalogue
            {
                Id           = Guid.NewGuid(),
                Details      = i.Details.Trim().ToLower(),
                Name         = i.Name.Trim().ToLower(),
                Path         = i.Path.Trim().ToLower(),
                Category     = i.Category.Trim().ToLower(),
                Tags         = i.Tags.Trim().ToLower(),
                TileImageUrl = i.TileImageUrl.Trim().ToLower(),
                IsActive     = true
            });

            if (catalogue == null)
            {
                _catalogueRepository.CreateItem(new Catalogues
                {
                    CatalogueList = catalogues,
                    Id            = catalogueId,
                    IsActive      = true,
                    Type          = item.Type.Trim().ToLower()
                });
            }
            else
            {
                var catalogueToUpdate = _catalogueRepository.GetItem(k => k.Type.ToLower() == item.Type.Trim().ToLower());

                List <Catalogue> newCatalogues = new List <Catalogue>();
                newCatalogues = catalogueToUpdate.CatalogueList.ToList();
                newCatalogues.Add(catalogues.FirstOrDefault());

                catalogueToUpdate.CatalogueList = newCatalogues;

                _catalogueRepository.UpdateItem(j => j.Id == catalogue.Id, catalogueToUpdate);
            }

            ResetGlobals();

            return(catalogueId.ToString());
        }