public async Task <int> PostAsync([FromBody] CmsItemVm value) { //We use Nullable notation, we no longer need to nullcheck, i think! //if (value is null) //{ // Logger.LogError($"Trying to create a new item with no data! Redirection to base {} "); //} //var json = JsonSerializer.Deserialize(value, typeof(CmsItem)); var cmsitem = new CmsItem { ItemData = value.ItemData, ItemId = value.ItemId, ItemType = value.ItemType }; await DbContext.CmsItems.AddAsync(cmsitem); return(await DbContext.SaveChangesAsync()); }
public int Put(Guid?id, [FromBody] CmsItemVm value) { if (id is null) { //Trying to put without ID, will redirect to post. RedirectToAction(nameof(PostAsync), value); } var item = DbContext.CmsItems.Where(c => c.Id.Equals(id)).FirstOrDefault(); item = new CmsItem { ItemId = value.ItemId, ItemData = value.ItemData, ItemType = value.ItemType, Url = value.Url }; DbContext.CmsItems.Update(item); return(DbContext.SaveChanges()); }