public ResponseResult<bool> Register(RequestRegister request, string hostAddress) { Console.WriteLine("Entered Register with Params"); Console.WriteLine(request.userId); Console.WriteLine(request.protocol); Console.WriteLine(hostAddress); Console.WriteLine("End Register"); var userRegistered = DynamoDbClientWithCache.Instance.Get<short, User>(request.userId); if (userRegistered == null) throw new UnauthorizedUserException(RegisterExceptionMessage.ForUnauthorized("ID Not Issued")); if (userRegistered.accesskey != request.AccessKey) throw new UnauthorizedAccessException(RegisterExceptionMessage.ForUnauthorized("Access Key Incorrect")); var user = new User() { id = request.userId, server_host = hostAddress, protocol = request.protocol }; DynamoDbClientWithCache.Instance.Set<short, User>(user.id, user); return new ResponseResult<bool>(true); }
public override void Run() { var req = new UpdateItemRequest() { TableName = "counters", UpdateExpression = "ADD id :incr", ReturnValues = new ReturnValue("UPDATED_NEW") }; req.Key.Add("table_name", new AttributeValue("user")); req.ExpressionAttributeValues.Add(":incr", new AttributeValue() { N = "1" }); req.UpdateExpression = "ADD id :incr"; var resp = DynamoDBClient.Instance.UpdateItem(req); short newId = short.Parse(resp.Attributes["id"].N); using (var ctx = new DynamoDBContext(DynamoDBClient.Instance)) { User user = new User() { id = newId, accesskey = Guid.NewGuid() }; ctx.Save(user); } Console.WriteLine("User [" + newId + "] has been added"); if (Program.IsInteractive) Program.ToMainMenu(); }