Exemplo n.º 1
0
        public async Task <IActionResult> UpdateKey([FromQuery] TKey newKey, TKey oldKey)
        {
            if (newKey == null || oldKey == null)
            {
                return(BadRequest(new Error()
                {
                    Message = "Must supply both newKey and oldKey ..."
                }));
            }
            await Task.Run(() => _service.UpdateKey(_tableName, _keyName, newKey, oldKey));

            //Use Reflection : When we have a string OF a property and want to access a property value in runtime
            //Get type,
            //Get Property (binding Flags: ignore case sensitive, instance (not static), public) ,
            //Get Value
            TEntity entity = _service.GetOne <TEntity>(item => item.GetValue(_keyName).Equals(newKey));

            // await _hubContext.Clients.Group(_tableName).SendAsync(_clientMethod, "Update", entity);
            return(_GetEntityResult(entity));
        }
Exemplo n.º 2
0
 // update Only an entity PK -- [Used by Admins Only]
 public async Task UpdateKey(TKey newKey, TKey oldKey)
 {
     _clientMethod = "UpdatedKey";
     // if method params are null return error
     if (newKey == null || oldKey == null)
     {
         await Clients.All.SendAsync(_clientMethod, new Response <String>() { Error = "Must supply both newKey and oldKey ..." });
     }
     try
     {
         // update entity Key in DB
         _service.UpdateKey(_tableName, _keyName, newKey, oldKey);
         // get the updatedKey entity
         TEntity entity = _service.GetOne <TEntity>(item => item.GetValue(_keyName).Equals(newKey));
         // if everything is ok, return the full user obj with all inserted values
         await Clients.All.SendAsync(_clientMethod, new Response <TEntity>() { Data = entity });
     }
     catch (Exception ex)
     {
         await Clients.All.SendAsync(_clientMethod, new Response <Exception>() { Exception = ex });
     }
 }