public async Task <bool> BulkMerge(List <LocationLog> LocationLogs) { List <LocationLogDAO> LocationLogDAOs = new List <LocationLogDAO>(); foreach (LocationLog LocationLog in LocationLogs) { LocationLogDAO LocationLogDAO = new LocationLogDAO(); LocationLogDAO.Id = LocationLog.Id; LocationLogDAO.PreviousId = LocationLog.PreviousId; LocationLogDAO.AppUserId = LocationLog.AppUserId; LocationLogDAO.Latitude = LocationLog.Latitude; LocationLogDAO.Longtitude = LocationLog.Longtitude; LocationLogDAO.UpdateInterval = LocationLog.UpdateInterval; LocationLogDAO.CreatedAt = StaticParams.DateTimeNow; LocationLogDAO.UpdatedAt = StaticParams.DateTimeNow; LocationLogDAOs.Add(LocationLogDAO); } await DataContext.BulkMergeAsync(LocationLogDAOs); return(true); }
public async Task <bool> Update(LocationLog LocationLog) { LocationLogDAO LocationLogDAO = DataContext.LocationLog.Where(x => x.Id == LocationLog.Id).FirstOrDefault(); if (LocationLogDAO == null) { return(false); } LocationLogDAO.Id = LocationLog.Id; LocationLogDAO.PreviousId = LocationLog.PreviousId; LocationLogDAO.AppUserId = LocationLog.AppUserId; LocationLogDAO.Latitude = LocationLog.Latitude; LocationLogDAO.Longtitude = LocationLog.Longtitude; LocationLogDAO.UpdateInterval = LocationLog.UpdateInterval; LocationLogDAO.UpdatedAt = StaticParams.DateTimeNow; await DataContext.SaveChangesAsync(); await SaveReference(LocationLog); return(true); }
public async Task <bool> Create(LocationLog LocationLog) { LocationLogDAO Previous = await DataContext.LocationLog .Where(x => x.AppUserId == LocationLog.AppUserId) .FirstOrDefaultAsync(); LocationLogDAO LocationLogDAO = new LocationLogDAO(); LocationLogDAO.PreviousId = Previous?.Id; LocationLogDAO.AppUserId = LocationLog.AppUserId; LocationLogDAO.Latitude = LocationLog.Latitude; LocationLogDAO.Longtitude = LocationLog.Longtitude; LocationLogDAO.UpdateInterval = LocationLog.UpdateInterval; LocationLogDAO.CreatedAt = StaticParams.DateTimeNow; LocationLogDAO.UpdatedAt = StaticParams.DateTimeNow; DataContext.LocationLog.Add(LocationLogDAO); await DataContext.SaveChangesAsync(); LocationLog.Id = LocationLogDAO.Id; await SaveReference(LocationLog); return(true); }
private async Task SaveReference(AppUser AppUser) { List <LocationLogDAO> LocationLogDAOs = await DataContext.LocationLog .Where(x => x.AppUserId == AppUser.Id).ToListAsync(); LocationLogDAOs.ForEach(x => x.DeletedAt = StaticParams.DateTimeNow); if (AppUser.LocationLogs != null) { foreach (LocationLog LocationLog in AppUser.LocationLogs) { LocationLogDAO LocationLogDAO = LocationLogDAOs .Where(x => x.Id == LocationLog.Id && x.Id != 0).FirstOrDefault(); if (LocationLogDAO == null) { LocationLogDAO = new LocationLogDAO(); LocationLogDAO.Id = LocationLog.Id; LocationLogDAO.PreviousId = LocationLog.PreviousId; LocationLogDAO.AppUserId = AppUser.Id; LocationLogDAO.Latitude = LocationLog.Latitude; LocationLogDAO.Longtitude = LocationLog.Longtitude; LocationLogDAO.UpdateInterval = LocationLog.UpdateInterval; LocationLogDAOs.Add(LocationLogDAO); LocationLogDAO.CreatedAt = StaticParams.DateTimeNow; LocationLogDAO.UpdatedAt = StaticParams.DateTimeNow; LocationLogDAO.DeletedAt = null; } else { LocationLogDAO.Id = LocationLog.Id; LocationLogDAO.PreviousId = LocationLog.PreviousId; LocationLogDAO.AppUserId = AppUser.Id; LocationLogDAO.Latitude = LocationLog.Latitude; LocationLogDAO.Longtitude = LocationLog.Longtitude; LocationLogDAO.UpdateInterval = LocationLog.UpdateInterval; LocationLogDAO.UpdatedAt = StaticParams.DateTimeNow; LocationLogDAO.DeletedAt = null; } } await DataContext.LocationLog.BulkMergeAsync(LocationLogDAOs); } if (AppUser.AppUserAppUserMappingAppUsers != null) { await DataContext.AppUserAppUserMapping .Where(x => x.AppUserId == AppUser.Id).DeleteFromQueryAsync(); List <AppUserAppUserMappingDAO> AppUserAppUserMappingDAOs = AppUser.AppUserAppUserMappingAppUsers .Select(x => new AppUserAppUserMappingDAO { AppUserId = AppUser.Id, FriendId = x.FriendId, CreatedAt = x.CreatedAt, UpdatedAt = StaticParams.DateTimeNow, DeletedAt = x.DeletedAt, }).ToList(); await DataContext.BulkMergeAsync(AppUserAppUserMappingDAOs); } if (AppUser.AppUserAppUserMappingFriends != null) { await DataContext.AppUserAppUserMapping .Where(x => x.FriendId == AppUser.Id).DeleteFromQueryAsync(); List <AppUserAppUserMappingDAO> AppUserAppUserMappingDAOs = AppUser.AppUserAppUserMappingFriends .Select(x => new AppUserAppUserMappingDAO { AppUserId = x.AppUserId, FriendId = AppUser.Id, CreatedAt = x.CreatedAt, UpdatedAt = StaticParams.DateTimeNow, DeletedAt = x.DeletedAt, }).ToList(); await DataContext.BulkMergeAsync(AppUserAppUserMappingDAOs); } }