123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using Microsoft.EntityFrameworkCore;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using UnivateProperties_API.Containers.Property;
- using UnivateProperties_API.Containers.Timeshare;
- using UnivateProperties_API.Context;
- using UnivateProperties_API.Model.Logging;
-
- namespace UnivateProperties_API.Repository.Logging
- {
- public class SearchLogRepository : ISearchLogRepository
- {
- private readonly DataContext _dbContext;
-
- public SearchLogRepository(DataContext dbContext)
- {
- _dbContext = dbContext;
- }
-
- public List<SearchLog> Get(Func<SearchLog, bool> where)
- {
- return _dbContext.SearchLogs.Where(where).ToList();
- }
-
- public List<SearchLog> GetAll()
- {
- return _dbContext.SearchLogs.ToList();
- }
-
- public SearchLog GetDetailed(Func<SearchLog, bool> first)
- {
- var item = _dbContext.SearchLogs.FirstOrDefault(first);
- return item;
- }
-
- public List<SearchLog> GetDetailedAll()
- {
- return _dbContext.SearchLogs.ToList();
- }
-
- public List<SearchDisplay> GetSearches()
- {
- var list = new List<SearchDisplay>();
- var logs = GetAll();
- foreach (SearchLog log in logs)
- {
- var searchObject = JsonConvert.DeserializeObject<SearchObject>(log.Search);
- list.Add(new SearchDisplay() {
- Date = string.Format("{0:yyyy-MM-dd}", log.Created),
- Time = string.Format("{0:HH:mm:ss}", log.Created),
- Type = log.Type,
- UserName = searchObject.UserName,
- Property = searchObject.Property,
- Value = searchObject.Value
- });
- }
- return list;
- }
-
- public void Insert(SearchLog item)
- {
- _dbContext.SearchLogs.Add(item);
- Save();
- }
-
- public void Insert(IEnumerable<SearchLog> items)
- {
- foreach (var item in items)
- {
- _dbContext.SearchLogs.Add(item);
- Save();
- }
- }
-
- public void Remove(SearchLog item)
- {
- _dbContext.SearchLogs.Remove(item);
- Save();
- }
-
- public void Remove(IEnumerable<SearchLog> items)
- {
- foreach (var item in items)
- {
- _dbContext.SearchLogs.Remove(item);
- Save();
- }
- }
-
- public void RemoveAtId(int item)
- {
- var searchLog = Get(x => x.Id == item).FirstOrDefault();
- if (searchLog != null)
- {
- _dbContext.SearchLogs.Remove(searchLog);
- Save();
- }
- }
-
- public void Save()
- {
- _dbContext.SaveChanges();
- }
-
- public void SaveSearch(SearchObject item)
- {
- var searchLog = new SearchLog
- {
- Type = item.Type,
- Search = JsonConvert.SerializeObject(item)
- };
- _dbContext.SearchLogs.Add(searchLog);
- Save();
- }
-
- public void Update(SearchLog item)
- {
- _dbContext.Entry(item).State = EntityState.Modified;
- Save();
- }
-
- public int NewId()
- {
-
- return 0;
- }
- }
- }
|