Exemple #1
0
        public static TModel FromArticle <TModel>(Article article) where
        TModel : ArticleApiModel, new()
        {
            var model = new TModel();

            model.Id = article.Id;

            model.AuthorId = article.AuthorId;

            model.Slug = article.Slug;

            model.FeaturedImageUrl = article.FeaturedImageUrl;

            model.Title = article.Title;

            model.HtmlContent = article.HtmlContent;

            model.Published = article.Published;

            model.IsPublished = article.IsPublished;

            model.Author = AuthorApiModel.FromAuthor(article.Author);

            model.Tags = article.Tags.Select(t => TagApiModel.FromTag(t)).ToList();

            model.Categories = article.Categories.Select(c => CategoryApiModel.FromCategory(c)).ToList();

            return(model);
        }
Exemple #2
0
        public IHttpActionResult Update([FromBody] TagApiModel tagApiModel)
        {
            var tagModel = _mapper.Map <TagModel>(tagApiModel);

            _tagService.Update(tagModel);

            return(Ok());
        }
Exemple #3
0
        public async Task <SaveTagCommand.Response> HandleSaveTagCommand(SaveTagCommand.Request request, CancellationToken cancellationToken, SaveTagCommand.Response response)
        {
            var tag = await _context.Tags.FindAsync(response.TagId);

            await _hubContext.Clients.All.SendAsync("message", new
            {
                Type    = "[Tag] Saved",
                Payload = new { tag = TagApiModel.FromTag(tag) }
            });

            return(response);
        }
        public static TModel FromNote <TModel>(Note note) where
        TModel : NoteApiModel, new()
        {
            var model = new TModel();

            model.Id       = note.Id;
            model.TenantId = note.TenantId;
            model.Title    = note.Title;
            model.Body     = note.Body;
            model.Slug     = note.Slug;
            model.Tags     = note.NoteTags.Select(x => TagApiModel.FromTag(x.Tag)).ToList();
            return(model);
        }
Exemple #5
0
        public static NoteApiModel FromNote(Note note, bool includeTags = true)
        {
            var model = new NoteApiModel
            {
                NoteId = note.NoteId,
                Title  = note.Title,
                Slug   = note.Slug,
                Body   = note.Body
            };

            if (includeTags)
            {
                model.Tags = note.NoteTags.Select(x => TagApiModel.FromTag(x.Tag)).ToList();
            }

            return(model);
        }
        public async Task <IActionResult> GetTag([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tag = await _context.Tags
                      .Include(t => t.ContactTags)
                      .SingleOrDefaultAsync(m => m.Id == id);

            if (tag == null)
            {
                return(NotFound());
            }

            var contacts = new List <ContactApiModel>();

            foreach (var contactTag in tag.ContactTags)
            {
                foreach (var contact in _context.Contacts.Where(c => c.Id == contactTag.ContactId))
                {
                    contacts.Add(new ContactApiModel {
                        Id        = contact.Id,
                        FirstName = contact.FirstName,
                        LastName  = contact.LastName
                    });
                }
            }

            var tagToReturn = new TagApiModel {
                Id       = tag.Id,
                Name     = tag.Name,
                Contacts = contacts,
                Count    = contacts.Count
            };

            return(Ok(tagToReturn));
        }