public IActionResult Post([FromBody] TopicModelIn topicIn) { if (ModelState.IsValid) { try { var topic = mapper.Map <TopicModelIn, TopicEntity>(topicIn); var id = topicLogic.Add(topic); var addedTopic = topicLogic.GetByName(topic.Name); var addedTopicOut = mapper.Map <TopicEntity, TopicModelOut>(addedTopic); return(Created("Posted succesfully", addedTopicOut)); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } else { return(BadRequest(ModelState)); } }
private void importTopics(ICollection <Parameter> parameters, ref Tuple <int, int>[] result, IGenericImporter genericInterface) { try { ICollection <TopicEntity> importedTopicsCollection = genericInterface.GetTopics(parameters); List <TopicEntity> importedTopics = importedTopicsCollection.ToList(); int totalTopics = importedTopics.Count; int succesfulTopics = 0; foreach (TopicEntity importedTopic in importedTopics) { try { topicLogic.Add(importedTopic); succesfulTopics++; } catch (ArgumentException) { } } result[1] = new Tuple <int, int>(totalTopics, succesfulTopics); } catch (ArgumentException e) { throw new ArgumentException(e.Message); } }