async Task IEventHandler <UserPropertyChanged> .HandleAsync(UserPropertyChanged payload) { UserPropertyModel model = models.FirstOrDefault(c => c.Key == payload.PropertyKey); if (model == null) { models.Add(model = new UserPropertyModel(payload.PropertyKey, null)); } model.Value = payload.Value; await localStorage.SaveAsync(models); }
public async Task <IActionResult> PutAsync(UserPropertyModel model) { Ensure.NotNull(model, "model"); string userId = HttpContext.User.FindUserId(); if (userId == null) { return(Unauthorized()); } if (options.Keys == null || !options.Keys.Contains(model.Key)) { return(BadRequest()); } UserPropertyValue entity = await db.UserProperties.FirstOrDefaultAsync(p => p.Key == model.Key && p.UserId == userId); if (entity == null) { if (model.Value != null) { entity = new UserPropertyValue() { UserId = userId, Key = model.Key, Value = model.Value }; db.UserProperties.Add(entity); } } else if (model.Value == null) { db.UserProperties.Remove(entity); } else { entity.Value = model.Value; } if (entity != null) { await db.SaveChangesAsync(); } return(Ok()); }
public async Task <object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next) { if (query is ListUserProperty listAll) { await EnsureListAsync(null, next, listAllQuery); return(models.Select(c => c.Clone()).ToList()); } else if (query is FindUserProperty find) { await EnsureListAsync(dispatcher, null, listAllQuery); UserPropertyModel model = models.FirstOrDefault(m => m.Key == find.Key); if (model != null) { return(model.Value); } } return(await next(query)); }
public MessengerSourceViewModel() { userPropertyModel = new UserPropertyModel(); }