public void AddSearchResult(DTO.SearchResultDTO abs) { try { using (var context = new Models.EnterpriseContext()) { var addRecord = new Models.SearchResultDTO { TrackId = abs.TrackId, TrackName = abs.TrackName, ArtistName = abs.ArtistName, Category = abs.Category, UserAgent = abs.UserAgent, UserIP = abs.UserIP, ClickCount = 1, RowCreateTS = DateTime.Now, RowMaintainedTS = DateTime.Now }; context.SearchResultCounters.Add(addRecord); context.SaveChanges(); } } catch (Exception e) { throw e; } }
public void UpdateCounter(long id, long clickCount) { try { using (var cntxt = new Models.EnterpriseContext()) { var cupdate = new Models.SearchResultDTO { Id = id, ClickCount = clickCount + 1, RowMaintainedTS = DateTime.Now }; cntxt.SearchResultCounters.Attach(cupdate); cntxt.Entry(cupdate).Property(x => x.ClickCount).IsModified = true; cntxt.Entry(cupdate).Property(x => x.RowMaintainedTS).IsModified = true; cntxt.SaveChanges(); } } catch (Exception e) { throw e; } }