public async Task <IActionResult> PageViewed(PageViewed pageViewedItem) { var visitorItem = new VisitorItem { Id = pageViewedItem.SessionId }; context.VisitorItem.Attach(visitorItem); switch (pageViewedItem.PageType) { case "Blogs": visitorItem.ViewedBlogs = true; context.Entry(visitorItem).Property(x => x.ViewedBlogs).IsModified = true; break; case "Projects": visitorItem.ViewedProjects = true; context.Entry(visitorItem).Property(x => x.ViewedProjects).IsModified = true; break; case "About": visitorItem.ViewedAbout = true; context.Entry(visitorItem).Property(x => x.ViewedAbout).IsModified = true; break; default: return(BadRequest($"Invalid Page Type {pageViewedItem.PageType}")); } await context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutVisitor(long id, Visitor visitor) { if (id != visitor.Id) { return(BadRequest()); } _context.Entry(visitor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VisitorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }