Ejemplo n.º 1
0
        public async Task <Topic> Update(TopicDetailed topic)
        {
            var dbTopic = await dbcontext.Topics.FirstOrDefaultAsync(t => t.Id == topic.Id);

            if (dbTopic is null)
            {
                return(null);
            }
            if (topic.Ancestor != null)
            {
                var ancestor = await dbcontext.Topics.FirstOrDefaultAsync(t => t.Id == topic.Ancestor.Id);

                if (ancestor != null)
                {
                    dbTopic.Ancestor = ancestor;
                }
            }
            else
            {
                dbTopic.Ancestor   = null;
                dbTopic.AncestorId = null;
            }
            dbTopic.Name = topic.Name;
            Console.WriteLine(dbTopic.Ancestor == null ? "The dbtopic's ancestor is null":"wtf");
            await dbcontext.SaveChangesAsync();

            return(topic);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Topic> > UpdateTopic(TopicDetailed topicDetailed)
        {
            var ret = await topicService.Update(topicDetailed);

            if (ret == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(ret));
            }
        }
Ejemplo n.º 3
0
        public async Task <Topic> Store(TopicDetailed topic)
        {
            DbTopic ancTopic = (topic.Ancestor == null)?null: await dbcontext.Topics.SingleOrDefaultAsync(t => t.Id == topic.Ancestor.Id);

            var dbTopic = new DbTopic()
            {
                Name     = topic.Name,
                Ancestor = ancTopic,
            };
            var res = await dbcontext.Topics.AddAsync(dbTopic);

            await dbcontext.SaveChangesAsync();

            return(DbMapper.MapDbTopic(res.Entity));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Topic> > CreateTopic([FromBody] TopicDetailed topic)
        {
            var created = await topicService.Store(topic);

            return(Created("/api/topics/" + created.Id, created));
        }
Ejemplo n.º 5
0
 public async Task <Topic> Update(TopicDetailed topic)
 {
     return(await topicRepo.Update(topic));
 }
Ejemplo n.º 6
0
 public async Task <Topic> Store(TopicDetailed topic)
 {
     return(await topicRepo.Store(topic));
 }