public void Put(int id, [FromBody] JsonLinkRecord jsonLinkRecord) { var linkRecord = linkRecordRepository.GetById(id); linkRecord.Url = jsonLinkRecord.Url; linkRecord.Title = jsonLinkRecord.Title; linkRecord.Note = jsonLinkRecord.Note; linkRecord.CategoryId = GetIdCategory(jsonLinkRecord.Category); linkRecord.OriginalUrlId = GetIdOriginalUrl(jsonLinkRecord.OriginalUrl); linkRecord.LanguageId = GetIdLanguage(jsonLinkRecord.Language); linkRecord.TypeId = GetIdType(jsonLinkRecord.Type); if (linkRecordRepository.Update(linkRecord)) { foreach (var item in jsonLinkRecord.Tags) { if (tagRepository.GetByName(item) == null) { tagRepository.Insert(item); } } var newTagsForLink = jsonLinkRecord.Tags.Select(s => new TagsLinkRecord { TagId = tagRepository.GetByName(s).Id, LinkRecordId = id }).ToList(); tagsLinkRecordRepository.Update(newTagsForLink); } }
public void Post([FromBody] JsonLinkRecord jsonLinkRecord) { LinkRecord linkRecord = new LinkRecord { CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"), Url = jsonLinkRecord.Url, Title = jsonLinkRecord.Title, Note = jsonLinkRecord.Note, CategoryId = GetIdCategory(jsonLinkRecord.Category), OriginalUrlId = GetIdOriginalUrl(jsonLinkRecord.OriginalUrl), LanguageId = GetIdLanguage(jsonLinkRecord.Language), TypeId = GetIdType(jsonLinkRecord.Type), }; if (linkRecordRepository.Insert(linkRecord)) { var idNewLinkRecord = linkRecordRepository.GetAll().Single(c => c.Url == jsonLinkRecord.Url).Id; AddCollectionTags(jsonLinkRecord.Tags, idNewLinkRecord); } }