Esempio n. 1
0
        public async Task <IActionResult> Post([FromBody] CategoryAreaDto categoryAreaDto)
        {
            var categoryArea = new CategoryArea
            {
                Name        = categoryAreaDto.Name,
                Description = categoryAreaDto.Description
            };
            await _categoryAreaService.CreateAsync(categoryArea);

            categoryAreaDto.Id = categoryArea.Id;
            return(CreatedAtRoute("GetCategoryArea", new { id = categoryAreaDto.Id }, categoryAreaDto));
        }
Esempio n. 2
0
        public async Task <ImportResult <CategoryArea> > Import(string csvContent)
        {
            var result = new ImportResult <CategoryArea>
            {
                ImportedEntities = new List <CategoryArea>(),
                ErrorMessages    = new List <string>()
            };

            int counter = 0;
            var records = _recordExtractor.GetRecords <CategoryAreaRecord, CategoryAreaRecordMap>(csvContent);

            foreach (var record in records)
            {
                counter++;
                if (string.IsNullOrWhiteSpace(record.Name))
                {
                    AddError(result, $"[{counter}]: Area name is null or empty.");
                    continue;
                }

                var categoryArea = await _categoryAreaService.ReadByNameAsync(record.Name);

                if (categoryArea != null)
                {
                    AddError(result, $"[{counter}]: Area with name: {record.Name} already exists.");
                    continue;
                }

                categoryArea = new CategoryArea
                {
                    Name        = record.Name,
                    Description = record.Description
                };
                await _categoryAreaService.CreateAsync(categoryArea);

                result.ImportedEntities.Add(categoryArea);
            }

            return(result);
        }