public IActionResult SynchronizeData([FromRoute] string userId, [FromBody] SynchronisationRequest request) { SynchronisationRequest response = users.Synchronisation(userId, request); return(Ok(response)); }
public SynchronisationRequest Synchronisation(string userId, SynchronisationRequest request) { var collection = db.GetCollection <User>("Users"); var user = collection.FindSync(us => us.UserId == userId).FirstAsync().Result; if (user.NicknameDateOfChange < request.NicknameDateOfChange) { user.NicknameDateOfChange = request.NicknameDateOfChange; user.UserNickname = request.UserNickname; } List <Tracking> collectionToReturn = user.ChangeTrackingCollection(request.TrackingCollection); var filter = Builders <User> .Filter.Eq(us => us.UserId, user.UserId); collection.ReplaceOneAsync(filter, user); SynchronisationRequest toReturn = new SynchronisationRequest() { NicknameDateOfChange = user.NicknameDateOfChange, UserNickname = user.UserNickname, TrackingCollection = collectionToReturn }; return(toReturn); }
public IActionResult TestSync([FromRoute] string userId, [FromBody] SynchronisationRequest request) { if (!_manager.FindUser(userId)) { return(BadRequest("User does not exist")); } var response = _manager.SynchronizeData(userId, request.NicknameDateOfChange, userId, request.trackingCollection); return(Ok(response)); }
public IActionResult SynchronizeData([FromBody] SynchronisationRequest request) { var userId = HttpContext.GetUserId(); if (!_manager.FindUser(userId)) { return(BadRequest("User does not exist")); } var response = _manager.SynchronizeData(userId, request.NicknameDateOfChange, request.UserNickname, request.trackingCollection); return(Ok(response)); }
public SynchronisationRequest SynchronizeData(string userId, DateTimeOffset nicknameDateOfChange, string userNickname, List <Tracking> trackingCollection) { var user = _userRepository.GetUserData(userId); if (user.NicknameDateOfChange < nicknameDateOfChange) { user.NicknameDateOfChange = nicknameDateOfChange; user.UserNickname = userNickname; } List <Tracking> collectionToReturn = user.ChangeTrackingCollection(trackingCollection); _userRepository.SaveUserData(user); SynchronisationRequest toReturn = new SynchronisationRequest() { NicknameDateOfChange = user.NicknameDateOfChange, UserNickname = user.UserNickname, trackingCollection = collectionToReturn }; return(toReturn); }